Printer properties not inherited by objects that use the default printer

Article translations Article translations
Article ID: 290293 - View products that this article applies to.
This article was previously published under Q290293
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) or a Microsoft Office Access 2007 database (.accdb). This article also applies to a Microsoft Access project (.adp).
Expand all | Collapse all

On This Page

SYMPTOMS

After you programmatically change properties of the Application.Printer object, forms and reports that use the default printer do not automatically inherit these settings.

CAUSE

Saved forms and reports store printer information as part of their definition. When you preview or print saved forms and reports, these objects use the printer information that is stored within them instead of inheriting the settings from the Application.Printer object.

RESOLUTION

There are two possible workarounds to force the report to use the current printer settings.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Set the Printer Property to Application.Printer

After you customize the properties for the Application.Printer object, set the Printer property of the form or report to the Application.Printer object. This forces the form or the report to destroy its current DEVMODE structure and to inherit a new one from the Application.Printer object.

Note that this approach is good for temporarily changing the object's printer properties. The printer settings will not be stored with the object unless you explicitly save the object afterward. This also causes the object to be set to Specific Printer for the period of time that it is open.

To set the object's Printer property to the Application.Printer object, follow these steps:
  1. Open the sample database Northwind.mdb.
  2. Close the Main Switchboard form when it appears.
  3. Press ALT+F11 to open Visual Basic Editor.
  4. On the Insert menu, click Module.
  5. Add the following Visual Basic for Applications code to the new module:
    Sub ChangePrinterSettingsForReport()
       Dim rpt As Access.Report
       Dim prtr As Access.Printer
       
       Set Application.Printer = Nothing
       Set prtr = Application.Printer
       
       'Set the default printer's orientation to landscape
       prtr.Orientation = acPRORLandscape
    
       'Set the default printer's paper size to legal
       prtr.PaperSize = acPRPSLegal
    
       'Print Preview the Alphabetical List of Products Report
       DoCmd.OpenReport "Alphabetical List of Products", acPreview
       Set rpt = Reports("Alphabetical List of Products")
    
       'Set the Printer property of the report to the
       'Application.Printer object
       Set rpt.Printer = prtr
    
       'Uncomment the following line if you wish to save the object
       'with the current settings
       'DoCmd.Save acReport, rpt.Name
    
    End Sub
    					
  6. Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.
  7. On the File menu, click Close and Return to Microsoft Access.
  8. In Microsoft Office Access 2003 or in Microsoft Access 2002, click Page Setup on the File menu, , and then click the Page tab.

    In Microsoft Office Access 2007, click the Microsoft Office Button, point to Print, and then click Print Preview. On the Print Preview tab, click Page Setup in the Page Layout group, and then click the Page tab.

    Note that the report's Paper Size is set to Legal, and the Orientation is set to Landscape.
  9. Close the report.
  10. In the Database window, print preview the Alphabetical List of Products report again. Note that the printer settings were not automatically saved with the report.

Assign the Printer Settings of the Object Directly

Another workaround is to programmatically set the printer settings of the object itself, instead of setting them to the Application.Printer property. Setting the individual properties of the object's Printer property is similar to the user manually changing printer settings within the Page Setup dialog box. When you programmatically set the object's printer settings directly, the settings are saved with the object automatically.

To set the object's printer settings directly, follow these steps:
  1. Open the sample database Northwind.mdb.
  2. Close the Main Switchboard form when it appears.
  3. Press ALT+F11 to open Visual Basic Editor.
  4. On the Insert menu, click Module.
  5. Add the following Visual Basic for Applications code to the new module:
    Sub ChangePrinterSettingsForReport()
       Dim rpt As Access.Report
      
       DoCmd.OpenReport "Alphabetical List of Products", acPreview
       Set rpt = Reports("Alphabetical List of Products")
          
       'Set the default printer's orientation to landscape
       rpt.Printer.Orientation = acPRORLandscape
    
       'Set the default printer's paper size to legal
       rpt.Printer.PaperSize = acPRPSLegal
    End Sub
    					
  6. Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.
  7. On the File menu, click Close and Return to Microsoft Access.
  8. On the File menu, click Page Setup, and then click the Page tab.

    In Microsoft Office Access 2007, click the Microsoft Office Button, point to Print, and then click Print Preview. On the Print Preview tab, click Page Setup in the Page Layout group, and then click the Page tab.

    Note that the report's Paper Size is set to Legal, and the Orientation is set to Landscape.
  9. Close the report.
  10. In the Database window, print preview the Alphabetical List of Products report again. Note that the printer settings were automatically saved with the report.

STATUS

This behavior is by design.

MORE INFORMATION

Forms and reports store a structure named DEVMODE as part of their definition. The DEVMODE structure is a Microsoft Windows structure that defines printer information for a particular object. For example, items such as paper size, paper bin, and orientation are stored as part of this structure. When you create a new form or report object, the form or report object automatically inherits the DEVMODE structure from the Application.Printer object. When you save the form or the report, the DEVMODE structure that was inherited automatically gets saved with it.

By default, the printer properties for the Application.Printer object will be the same as the default printer within Microsoft Windows. However, it is possible to programmatically change these properties so that Microsoft Access uses a different set of properties for the default printer. Tables, queries, views, and stored procedures do not store printer information as part of their definition. Therefore when you print tables, queries, views, or stored procedures, they will always use the current settings defined in the Application.Printer object.

Steps to Reproduce the Behavior

  1. In Access 2003 or in Access 2002, open the sample database Northwind.mdb.
  2. Close the Main Switchboard form when it appears.
  3. On the View menu, point to Database Objects, and then click Reports.
  4. Click the Alphabetical List of Products report in the Database window, and then on the File menu click Page Setup.
  5. Click the Page tab, and verify that the Default Printer option is selected under the Printer section of the dialog box.
  6. Click OK to close the Page Setup dialog box.
  7. On the Insert menu, click Module.
  8. Add the following Visual Basic for Applications code to the module:
    Sub ChangePrinterSettings()
       'Set the default printer's orientation to landscape
       Application.Printer.Orientation = acPRORLandscape
    
       'Set the default printer's paper size to legal
       Application.Printer.PaperSize = acPRPSLegal
    End Sub
    					
  9. Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.
  10. On the File menu, click Close and Return to Microsoft Access.
  11. On the View menu, point to Database Objects, and then click Queries.
  12. Click the Alphabetical List of Products query, and then on the File menu, click Print Preview.
  13. On the File menu, click Page Setup.
  14. Click the Page tab. Note that the Orientation option is set to Landscape and the Paper Size option is set to Legal as expected.
  15. Click Cancel to close the Page Setup dialog box, and then close the query.
  16. On the View menu, point to Database Objects, and then click Reports.
  17. In the Database window, click the Alphabetical List of Products report, and then click Preview.
  18. On the File menu, click Page Setup.
  19. Click the Page tab. Note that the Orientation option is set to Portrait and the Paper Size option is set to Letter, which differs from the settings made to the Application.Printer object.

Properties

Article ID: 290293 - Last Review: April 10, 2007 - Revision: 7.1
APPLIES TO
  • Microsoft Office Access 2007
  • Microsoft Office Access 2003
  • Microsoft Access 2002 Standard Edition
Keywords: 
kbappnote kbprogramming kbvba kbactivation kbprb kbprint KB290293

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com