J
Jeff G
All -
I've looked around for a soluton so that I can have a user print a report to
any printer that is installed on their system. I have most of it figured
out, but I'm running into a problem.
On my form, I have a field called lstPrinters. It is an unbound control
with a Row Source Type of Value List. I have the following code in the Form
Load event...
Private Sub Form_Load()
' Fill the list of printers
For Each objPrinter In Printers
Me.lstPrinters.AddItem objPrinter.DeviceName
Next
End Sub
I do have ojbPrinter declared by putting the following in the declaration...
Private objPrinter As Printer
I have a command button to Print the Report:
Private Sub cmdPrintReport_Click()
On Error Resume Next ' needed in case they click Cancel
Dim rpt As Access.Report
Dim prtr As Access.Printer
Set Application.Printer = Me.lstPrinters.Value
Set prtr = Application.Printer
'Set the default printer's orientation to landscape
prtr.Orientation = acPRORLandscape
'Set the default printer's paper size to legal
prtr.PaperSize = acPRPSLetter
'Print Preview the Alphabetical List of Products Report
DoCmd.OpenReport "rptRevenueActual", acViewNormal
Set rpt = Reports("rptRevenueActual")
DoCmd.Close acReport, "rptRevenueActual" ' close
'Set the Printer property of the report to the
'Application.Printer object
Set rpt.Printer = prtr
End Sub
The problem I'm running into is that I can select any printer other than the
default one, but when I click on the cmdPrintReport button, it only prints
to the default printer.
Is there something missing?
Thanks.
Jeff
I've looked around for a soluton so that I can have a user print a report to
any printer that is installed on their system. I have most of it figured
out, but I'm running into a problem.
On my form, I have a field called lstPrinters. It is an unbound control
with a Row Source Type of Value List. I have the following code in the Form
Load event...
Private Sub Form_Load()
' Fill the list of printers
For Each objPrinter In Printers
Me.lstPrinters.AddItem objPrinter.DeviceName
Next
End Sub
I do have ojbPrinter declared by putting the following in the declaration...
Private objPrinter As Printer
I have a command button to Print the Report:
Private Sub cmdPrintReport_Click()
On Error Resume Next ' needed in case they click Cancel
Dim rpt As Access.Report
Dim prtr As Access.Printer
Set Application.Printer = Me.lstPrinters.Value
Set prtr = Application.Printer
'Set the default printer's orientation to landscape
prtr.Orientation = acPRORLandscape
'Set the default printer's paper size to legal
prtr.PaperSize = acPRPSLetter
'Print Preview the Alphabetical List of Products Report
DoCmd.OpenReport "rptRevenueActual", acViewNormal
Set rpt = Reports("rptRevenueActual")
DoCmd.Close acReport, "rptRevenueActual" ' close
'Set the Printer property of the report to the
'Application.Printer object
Set rpt.Printer = prtr
End Sub
The problem I'm running into is that I can select any printer other than the
default one, but when I click on the cmdPrintReport button, it only prints
to the default printer.
Is there something missing?
Thanks.
Jeff