Programmatically Change Printer Options

Problem

You’ve tried using SendKeys to change printing options in the File Setup Page dialog, but this really isn’t satisfactory. Sometimes it works and sometimes it doesn’t, depending on the circumstances and the printer driver that’s loaded. Is there some way to modify printer options without using SendKeys?

Solution

Windows makes many of the printer driver settings available to applications, including the number of copies, page orientation, and page size. Access 2002 makes it easy to retrieve and modify these values, using the Printer property of forms and reports. This solution focuses on the print settings features of the Printer object and demonstrates how to read and write values in the Printer object.

To be able to modify printer settings for reports or forms in your own applications, follow these steps:

  1. Open the report in either preview or design view. (If you want to make your changes persistent, open the report in design view. If you want to apply changes for just this particular instance, open it in preview mode.)

  2. Modify some of the properties of the Printer object provided by your form or report. For example, the sample form works with a small subset of the available printer-specific properties, using code like this:

    DoCmd.OpenReport strReport, View:=acViewPreview
    With Reports(strReport).Printer
        Me.txtCopies = .Copies
        Me.grpOrientation = .Orientation
        Me.grpPaperSize = .PaperSize
    End With
  3. When you’re done working with the properties, ...

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.