Open the Print Dialog
If all you want is to open the print dialog using code then the following tidbit of code is all you need.
docmd.RunCommand acCmdPrint
Be sure to trap error number 2501 in case the user decides to cancel the action.
Program Which Printer Is Used Via VBA
On the other hand, if you are looking to hard code which printer is used to print a document then the following is addressed to you.
The following information came from Albert D. Kallal (Access MVP)
In access 2002 and later, there is a built in printer object, and it lets you switch the printer with ease.
You can use:
Set Application.Printer = Application.Printers("HP LaserJet Series II")
So, to save/switch, you can use:
Dim strDefaultPrinter as string
' get the currently defined default printer
strDefaultPrinter = Application.Printer.DeviceName
' switch to the printer of your choice
Set Application.Printer = Application.Printers("HP LaserJet Series II")
' do whatever....print reports
' Switch the application printer back to the original
Set Application.Printer = Application.Printers(strDefaultPrinter)
If you are using a earlier versions, then you can use my lightweight printer switch code here:
Printer change code.
This code simply allows you to change the default printer in code via ms-access. It is MINIMAL CODE. This code is both minimal in the size, and the also the ease in which it can be integrated into your application...
So, I do often build a form that displays a list of installed printers, and allow the user to select a printer. The above code example has such a form, but that old example is REALLY only of use for pre-A2002 applications.
So, for special forms, or things like invoice printer, I sill do NOT save which printer with the report (you *can* save the printer in ms-access, but the feature is not much use for users since if they install, or purchase a new printer..then the name changes..and your application will complain). So, while we do switch printers in code..we STILL avoid saving the particular printer to a given report. So, we always still set reports to use the default printer.
Since the margins, and portrait/landscape are saved with the report, then generally, just switching printers should do the trick if we kept the margins fairly large in the reports.”
Allen Browne also has a good utility for this purpose. More details can be found at:
Printer Selection Utility
Free utility for Microsoft Access 2002 and later, so a report can be assigned to a particular printer on each workstation.