R
RipperT
I have code behind a button that temporarily switches the printer from
default to another printer, prints a report, then switches back to the
default. The trouble is that, for the printer I am temporarily switching to,
some machines have one driver and others use another. I would like to use
error handling to first try one, and if absent, try the other, and if that
one is absent, display a custom message box and exit. I can account for the
first two possiblities, but how can I add the custom error message?
Private Sub cmdPrintRptHU1AWFormal_CC_Click()
On Error GoTo Err_cmdPrintRptHU1AWFormal_CC_Click
Dim stDocName As String
Dim strDefaultPrinter As String
'Get default printer
strDefaultPrinter = Application.Printer.DeviceName
'Change to secondary printer
Set Application.Printer = Application.Printers("HP LaserJet 9050 PCL6")
'Print document
stDocName = "rpt1FormalAW"
DoCmd.OpenReport stDocName, acNormal
'Switch back to default printer
Set Application.Printer = Application.Printers(strDefaultPrinter)
Exit_cmdPrintRptHU1AWFormal_CC_Click:
Exit Sub
Err_cmdPrintRptHU1AWFormal_CC_Click:
Set Application.Printer = Application.Printers("HP LaserJet 9050 PCL 6")
Resume Next
End Sub
Many thanks,
Rip
default to another printer, prints a report, then switches back to the
default. The trouble is that, for the printer I am temporarily switching to,
some machines have one driver and others use another. I would like to use
error handling to first try one, and if absent, try the other, and if that
one is absent, display a custom message box and exit. I can account for the
first two possiblities, but how can I add the custom error message?
Private Sub cmdPrintRptHU1AWFormal_CC_Click()
On Error GoTo Err_cmdPrintRptHU1AWFormal_CC_Click
Dim stDocName As String
Dim strDefaultPrinter As String
'Get default printer
strDefaultPrinter = Application.Printer.DeviceName
'Change to secondary printer
Set Application.Printer = Application.Printers("HP LaserJet 9050 PCL6")
'Print document
stDocName = "rpt1FormalAW"
DoCmd.OpenReport stDocName, acNormal
'Switch back to default printer
Set Application.Printer = Application.Printers(strDefaultPrinter)
Exit_cmdPrintRptHU1AWFormal_CC_Click:
Exit Sub
Err_cmdPrintRptHU1AWFormal_CC_Click:
Set Application.Printer = Application.Printers("HP LaserJet 9050 PCL 6")
Resume Next
End Sub
Many thanks,
Rip