I found this snippet of code on here that should print a report that you specify out of an Access DB.
When I run it - it fails on the line: Set NewPrinter = Application.Printers("MTR1-DL5210N-005") 'use your printer name here
Giving me this error: Invalid procedure call or argument
I assume that I'm to use the name of the printer as it appears on the network, but maybe I'm incorrect?
Code:
Private Sub PrintUS028()
Dim defPrinter As String, NewPrinter As Printer
'Get the default printer name
defPrinter = Application.Printer.DeviceName
'Create a new printer object
Set NewPrinter = Application.Printers("MTR1-DL5210N-005") 'use your printer name here
'Set the default printer to the new printer
Set Application.Printer = NewPrinter
'Open the report
DoCmd.OpenReport "US028-FINAL REPORT", acViewNormal 'use your actual report name here
'Print the report (the next line seems to print the report and the form so I removed it, if your report doesn't print then remove the apostrophe on the next line)
'DoCmd.PrintOut
'Close the report
DoCmd.Close acReport, "US028-FINAL REPORT", acSaveNo 'report name again!
'Reset the printer back to the default printer
Set NewPrinter = Application.Printers(defPrinter)
Set Application.Printer = NewPrinter
End Sub
When I run it - it fails on the line: Set NewPrinter = Application.Printers("MTR1-DL5210N-005") 'use your printer name here
Giving me this error: Invalid procedure call or argument
I assume that I'm to use the name of the printer as it appears on the network, but maybe I'm incorrect?