Mentioned
In
|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 290293 - Last Review: April 10, 2007 - Revision: 7.1 Printer properties not inherited by objects that use the default printerThis 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). On This PageSYMPTOMS 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 "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 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.
- 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 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. 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- In
Access 2003 or in Access 2002, open
the sample database Northwind.mdb.
- Close the Main Switchboard form when it appears.
- On the View menu, point to Database Objects, and then click Reports.
- Click the Alphabetical List of Products report in the Database window, and then on the File menu click Page Setup.
- Click the Page tab, and verify that the Default Printer option is selected under the Printer section of the dialog box.
- Click OK to close the Page Setup dialog box.
- On the Insert menu, click Module.
- 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
- 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 View menu, point to Database Objects, and then click Queries.
- Click the Alphabetical List of Products query, and then on the File menu, click Print Preview.
- On the File menu, click Page Setup.
- Click the Page tab. Note that the Orientation option is set to Landscape and the Paper Size option is set to Legal as expected.
- Click Cancel to close the Page Setup dialog box, and then close the query.
- On the View menu, point to Database Objects, and then click Reports.
- In the Database window, click the Alphabetical List of Products report, and then click Preview.
- On the File menu, click Page Setup.
- 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.
APPLIES TO- Microsoft Office Access 2007
- Microsoft Office Access 2003
- Microsoft Access 2002 Standard Edition
| kbappnote kbprogramming kbvba kbactivation kbprb kbprint KB290293 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please
|
 |
 |
 |
 |
 |
 |
 |
| |