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. Section 5.2.2 shows how to retrieve a list of available print devices and retrieve and set the default device. Section 5.6.2 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.

Access 2002 provides 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 ...

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.