M
madhouse
This is driving me totally mad...
Am trying to allow user to select printer and its properties using VBA with
Access 2003. Have form that maintains table with printer device and popeties
such as orientation, colourmode, printquality, pappersize.
Immediately before calling DoCmd.OpenReport I call a sub to set the
Application.Printer to the saved print device and properties.
Immediately after calling DoCmd.OpenReport while the report is open and in
preview mode I call the same sub but this time to set the report's printer
and properties.
BUT it works VERY erratically and I cannot see why! HELP!!! Sometimes the
preview matches the properites and the printer dialog's properies match the
properites, othert times it does'nt! WHAT AM I DOING WRONG!
Main Code is:
.....
.....
SetPrintProperties Application.Printer
DoCmd.OpenReport "rptStatement", acViewPreview, , , acWindowNormal, SQL
Reports!rptStatement.Printer = Application.Printer
SetPrintProperties Reports!rptStatement.Printer
......
......
Sub Code is:
Sub SetPrintProperties(ByRef Prt As Printer)
Dim cnxn As ADODB.Connection
Set cnxn = CurrentProject.Connection
Dim SqlData As New ADODB.Recordset
Dim Prtloop As Printer
SqlData.Open "SELECT * FROM Printer;", cnxn, adOpenForwardOnly,
adLockOptimistic
For Each Prtloop In Application.Printers
If Prtloop.DeviceName = SqlData!PrinterDefault Then
Set Prt = Prtloop 'Application.Printers(SqlData!PrinterDefault)
Prt.Orientation = SqlData!PrinterOrientation
Prt.ColorMode = SqlData!PrinterColourMode
Prt.PaperSize = SqlData!PrinterPaperSize
Prt.PrintQuality = SqlData!PrinterQuality
Exit For
End If
Next Prtloop
SqlData.Close
Set SqlData = Nothing
Set cnxn = Nothing
End Sub
Am trying to allow user to select printer and its properties using VBA with
Access 2003. Have form that maintains table with printer device and popeties
such as orientation, colourmode, printquality, pappersize.
Immediately before calling DoCmd.OpenReport I call a sub to set the
Application.Printer to the saved print device and properties.
Immediately after calling DoCmd.OpenReport while the report is open and in
preview mode I call the same sub but this time to set the report's printer
and properties.
BUT it works VERY erratically and I cannot see why! HELP!!! Sometimes the
preview matches the properites and the printer dialog's properies match the
properites, othert times it does'nt! WHAT AM I DOING WRONG!
Main Code is:
.....
.....
SetPrintProperties Application.Printer
DoCmd.OpenReport "rptStatement", acViewPreview, , , acWindowNormal, SQL
Reports!rptStatement.Printer = Application.Printer
SetPrintProperties Reports!rptStatement.Printer
......
......
Sub Code is:
Sub SetPrintProperties(ByRef Prt As Printer)
Dim cnxn As ADODB.Connection
Set cnxn = CurrentProject.Connection
Dim SqlData As New ADODB.Recordset
Dim Prtloop As Printer
SqlData.Open "SELECT * FROM Printer;", cnxn, adOpenForwardOnly,
adLockOptimistic
For Each Prtloop In Application.Printers
If Prtloop.DeviceName = SqlData!PrinterDefault Then
Set Prt = Prtloop 'Application.Printers(SqlData!PrinterDefault)
Prt.Orientation = SqlData!PrinterOrientation
Prt.ColorMode = SqlData!PrinterColourMode
Prt.PaperSize = SqlData!PrinterPaperSize
Prt.PrintQuality = SqlData!PrinterQuality
Exit For
End If
Next Prtloop
SqlData.Close
Set SqlData = Nothing
Set cnxn = Nothing
End Sub