Printer properties not inherited by objects that use the default printer (290293)
The information in this article applies to:
- Microsoft Office Access 2003
- Microsoft Access 2002
This article was previously published under Q290293 Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies to a Microsoft Access database (.mdb) and 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.
- 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 "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
- Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.
- On the File menu, click Close and Return to Microsoft Access.
- On the File menu, click Page Setup, and then click the Page tab. Note that the report's Paper Size is set to Legal, and the Orientation is set to Landscape.
- Close the report.
- 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:
- Open the sample database Northwind.mdb.
- Close the Main Switchboard form when it appears.
- 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
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
- Click in the sample procedure above, and then on the Run menu, click Run Sub/UserForm.
- On the File menu, click Close and Return to Microsoft Access.
- On the File menu, click Page Setup, and then click the Page tab. Note that the report's Paper Size is set to Legal, and the Orientation is set to Landscape.
- Close the report.
- 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.
Modification Type: | Major | Last Reviewed: | 6/23/2005 |
---|
Keywords: | kbappnote kbProgramming KbVBA kbactivation kbprb kbprint KB290293 |
---|
|