Retrieve Information About a Report or Form’s Selected Printer

Problem

Access’s File Page Setup dialog allows you to specify either the default printer or a specific printer for each printable object. You’d like to be able to find out, programmatically, which printer has been selected for an object and whether the object is set to print to the default printer. How can you retrieve that information?

Solution

In addition to the properties you’ve seen so far, the Printer object keeps track of the three pieces of information that Windows must know about an output device: the device name (for example, “HP LaserJet 4”), the driver name (“WINSPOOL”), and the output port (“LPT1:”). Access also keeps track of whether the report has been set to print to the default printer or to a specific printer, in the UseDefaultPrinter property of the report. You’ll use these properties to determine the information you need.

Load and run the form frmSelectedPrinters in 05-06.MDB. Figure 5-6 shows the form after rptReport3 is selected and the report’s output device, driver, and port are filled in on the form. Because this report was set up to print to the default printer, the “Printing to Default Printer” checkbox is selected.

frmSelectedPrinters, after selecting rptReport3

Figure 5-6. frmSelectedPrinters, after selecting rptReport3

The sample form uses this code to do its work:

Private Sub cboReportList_AfterUpdate( ) Dim strReport As String Dim rpt ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.