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 "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.
- 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 Pagetab.
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.
- 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
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.
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 Pagetab.
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.