Online Book Reader

Home Category

Access Cookbook - Ken Getz [118]

By Root 2117 0

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 hangs off of the report itself, while the rest of the properties discussed in this chapter are members of the Printer object returned by the report's Printer property. You may look for the UseDefaultPrinter property in the wrong place—remember, it's a property of the report.

The UseDefaultPrinter property becomes more important, as you'll see in the next section, when you want to change the output device at runtime. Because of the way the Printer object was designed, you cannot change the output device from the Open event of the report—you must change it from outside the report. The easiest way to do this is to change Access's default printer, then print the report, then put Access's default printer back to what it was. You can accomplish this only if the report has been set to print to Access's default printer. You can look at the UseDefaultPrinter property to determine if that's how the report was set up. (You cannot, however, change a report's UseDefaultPrinter property if it's open in preview or print mode—you can change it only when you've opened the report in design view.)

5.7. Choose an Output Device at Runtime


Problem


You'd like to be able to select an output device while your application is running without popping up the File → Page Setup dialog. Is there a way to present a list of available printers and have the chosen report print to the chosen device? For example, you want to print your reports to the printer sometimes and sometimes to the fax machine.

Solution


Though this topic sounds complex, its solution is really just a combination of other solutions in this chapter. The Solution in Recipe 5.2 shows how to retrieve a list of available print devices and retrieve and set the default device. The Solution in Recipe 5.6 shows how to determine if a given report or form is configured to print to the default printer. Given those two techniques, this solution shows you how to set a new output device, print the Access object (using the new default device), and then restore the original default device.

Starting with Access 2002, you'll find two ways in which you can change the output device: you can either change Access's default printer, then print your report to the new default printer; or you can simply change the report's selected output device. The first solution is easier and generally works better. The second requires an extra step (selecting the report on screen) but gives you more flexibility.

Load and run frmDefaultPrinterList from 05-07.MDB. Figure 5-7 shows the form in use, with the report rptReport3 selected and ready to print. Because rptReport3 has been configured to print to the default printer (you can open the File → Page Setup dialog to confirm this), the "Print to Default Printer" checkbox on the sample form is checked. You can choose a different output device from the combo box on the bottom of this form (of course, this will be interesting only if you happen to have more than one output device installed). If you choose a different output device (a fax driver, for example), the sample form will send the selected report to that output device.

Figure 5-7. frmDefaultPrinterList, ready to choose a new output device

The sample form also includes a checkbox ("Change Default Printer") that is available only if your selected report has been set up to print to the default printer. If so, you can elect to either change the default printer or select a new printer for the report. If the report has been designed so that it prints to a specific

Return Main Page Previous Page Next Page

®Online Book Reader