Microsoft KB Archive/290293

= Printer properties not inherited by objects that use the default printer =

Article ID: 290293

Article Last Modified on 4/10/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition

-



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).



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:  Open the sample database Northwind.mdb. Close the Main Switchboard form when it appears. Press ALT+F11 to open Visual Basic Editor. On the Insert menu, click Module.  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 &quot;Alphabetical List of Products&quot;, acPreview Set rpt = Reports(&quot;Alphabetical List of Products&quot;)

'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  Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.</li> On the File menu, click Close and Return to Microsoft Access.</li> 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.</li> Close the report.</li> 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.</li></ol>

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: <ol> Open the sample database Northwind.mdb.</li> Close the Main Switchboard form when it appears.</li> Press ALT+F11 to open Visual Basic Editor.</li> On the Insert menu, click Module.</li>  Add the following Visual Basic for Applications code to the new module: Sub ChangePrinterSettingsForReport Dim rpt As Access.Report DoCmd.OpenReport &quot;Alphabetical List of Products&quot;, acPreview Set rpt = Reports(&quot;Alphabetical List of Products&quot;) '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 </li> Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.</li> On the File menu, click Close and Return to Microsoft Access.</li> 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.</li> Close the report.</li> In the Database window, print preview the Alphabetical List of Products report again. Note that the printer settings were automatically saved with the report.</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

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
<ol> In Access 2003 or in Access 2002, open the sample database Northwind.mdb.</li> <li>Close the Main Switchboard form when it appears.</li> <li>On the View menu, point to Database Objects, and then click Reports.</li> <li>Click the Alphabetical List of Products report in the Database window, and then on the File menu click Page Setup.</li> <li>Click the Page tab, and verify that the Default Printer option is selected under the Printer section of the dialog box.</li> <li>Click OK to close the Page Setup dialog box.</li> <li>On the Insert menu, click Module.</li> <li> 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 </li> <li>Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.</li> <li>On the File menu, click Close and Return to Microsoft Access.</li> <li>On the View menu, point to Database Objects, and then click Queries.</li> <li>Click the Alphabetical List of Products query, and then on the File menu, click Print Preview.</li> <li>On the File menu, click Page Setup.</li> <li>Click the Page tab. Note that the Orientation option is set to Landscape and the Paper Size option is set to Legal as expected.</li> <li>Click Cancel to close the Page Setup dialog box, and then close the query.</li> <li>On the View menu, point to Database Objects, and then click Reports.</li> <li>In the Database window, click the Alphabetical List of Products report, and then click Preview.</li> <li>On the File menu, click Page Setup.</li> <li>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.</li></ol>

Additional query words: prb ACC2002 ACC2007

Keywords: kbappnote kbprogramming kbvba kbprb kbprint KB290293

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.