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?
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
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.
The sample form uses this code to do its work:
Private Sub cboReportList_AfterUpdate( ) Dim strReport As String Dim rpt As Report On Error GoTo HandleErrors strReport = Me.cboReportList DoCmd.OpenReport strReport, View:=acViewPreview, WindowMode:=acHidden With Reports(strReport) With .Printer Me.txtDevice = .DeviceName Me.txtDriver = .DriverName Me.txtPort = .Port End With Me.chkDefault = .UseDefaultPrinter End With ExitHere: DoCmd.Close acReport, strReport Exit Sub HandleErrors: MsgBox "Error: " & Error & " (" & Err & ")" Resume ExitHere End Sub
To retrieve printer information about forms or reports in your own applications, follow these steps:
DoCmd.OpenReport strReport, View:=acViewPreview, WindowMode:=acHidden
Use the DeviceName, DriverName, and Port properties of the report's Printer property to retrieve information about the report's output location:
With Reports(strReport) With .Printer Me.txtDevice = .DeviceName Me.txtDriver = .DriverName Me.txtPort = .Port ' Code removed. End With End With
Check the report's UseDefaultPrinter property to determine if the report has been set to print to the default printer:
With Reports(strReport) ' Code removed. Me.chkDefault = .UseDefaultPrinter End With
The UseDefaultPrinter property
The UseDefaultPrinter property becomes more important, as you'll see in the