DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 5. Printers

Printing output is a major component of any database product, and Access gives you a great deal of control over the "look" of your forms and reports. Programmatic control over the printer itself, however, has always been somewhat complex in Access. Windows provides rich and intricate support for output devices, and Access attempts to shield you from most of that intricacy. Sometimes, however, you do need to take control of your output devices; for example, you may need to change a particular device or a setting pertaining to a particular device. Historically, Access made this possible but not easy. However, starting with Access 2002, you can use the Printers collection with a Printer object that makes it relatively easy to accomplish the most common printing tasks. The sections in this chapter describe the details of handling your output devices using these new objects.

This chapter focuses on the Printers collection and the associated Printer object. We'll cover the properties of these objects in detail and show examples of their use. You'll be able to retrieve a list of all the installed printers and make a choice from that list, setting the new default Access printer. You'll learn how to modify margin settings in forms and reports, thereby avoiding the use of Access's File Page Setup dialog in your applications. You'll get help on changing printer options, such as the number of copies to print, the page orientation, and the printer resolution. Then you'll learn how to programmatically print the first page of a document from one paper tray and the rest of the pages from a different paper tray. This allows you to print the first page on letterhead paper and the rest on normal paper.

Finally, you'll find out how to determine which device has been selected to print a report and whether it's the default device. If it is, you can change the destination from your application, provide users with a choice of output devices, and print the object to a particular device. You'll also find a development tool that will run through all your reports and let you know which aren't set up to print to the default printer. By ensuring that all your reports print to the default printer, you will be able to send them to any output device simply by changing what Access thinks is the default printer.

Printing in Access 2000 Versus Access 2002 and Later

Access 2002 added functionality that fundamentally changed the ways in which you can interact with printing devices. Previously, determining the list of available printers and retrieving printer, layout, and device name information from individual Access objects was quite difficult. The code to handle these tasks in previous versions of Access was daunting, to say the least. The difference in the amount of code for the Access 2000 version of these examples compared to the later Access versions is astonishing—some examples that required several hundred lines of code in Access 2000 now require as little as 10 lines of code. To enable readers to use these techniques in Access 2000, we've provided the code examples in both styles. If you intend to use the examples in Access 2000, you'll need to remove the single form in each database that's specific to the later versions of Access. (The code in these forms simply won't compile in Access 2000, so the demos won't run correctly.) The Access 2000 code is far more complex than that for Access 2002 and later, and is the subject for a different time and place. If you intend to use that code, you'll need to dig seriously into the Access documentation, or find a resource that focuses on that particular information. We've provided the code here as a courtesy only and can neither support nor describe it in these pages.


    [ Team LiB ] Previous Section Next Section