Microsoft KB Archive/210283

= ACC2000: Using the PrtDevMode Property to Verify Custom Page Size =

Article ID: 210283

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210283



Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
You can use the PrtDevMode property to set or return printing device mode information specified for a form or report in the Print dialog box. When you use the PrtDevMode property, you need to keep certain printer driver characteristics in mind. This article identifies some points that you should consider.



MORE INFORMATION
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.

PrtDevMode Issues

 * Set only those members that the printer driver supports. For example, if you set a custom page size for a driver that does not support a custom page size, you may encounter unexpected results.

To find out whether you are using a driver that supports the Custom page size option, follow these steps:
 * Click Start, point to Settings, and then click Printers.
 * In the Printers window, right-click the name of the appropriate printer, and then click Properties.
 * In the Properties dialog box, click the Paper tab, and then view the Paper Size list.

If Custom does not appear in the list, you are not able to use the information in this article.
 * Set the PrtDevMode property's Fields member if you change any other member to let the printer driver know which members you are changing.
 * Change only the first 68 bytes of the PrtDevMode property. Printer drivers are able to store driver-specific information after the first 68 bytes; therefore, it is important not to overwrite this information.

Verify Report Page Size
To verify that a report has the correct page size, check the setting in the PrtDevMode property. The PrtDevMode property is available only in Visual Basic for Applications.

To create a Sub procedure that reports the page size from PrtDevMode, follow these steps:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Start Microsoft Access and open the sample database Northwind.mdb or the sample project NorthwindCS.adp.  Create a new module and, if it is not already there, type the following line in the Declarations section: Option Explicit   Type or paste the following lines to declare user-defined data types: Type zwtDevModeStr RGB As String * 94 End Type

Type zwtDeviceMode dmDeviceName As String * 16 dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperlength As Integer dmPaperWidth As Integer dmScale as Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Integer dmColor As Integer dmDuplex As Integer dmResolution As Integer dmTTOption As Integer dmCollate As Integer dmFormName As String * 16 dmPad As Long dmBits As Long dmPW As Long dmDFI As Long dmDRr as Long End Type   Type or paste the following procedure: Sub CheckCustomPage (rptName As String) ' The zwtDevModeStr and zwtDeviceMode types are defined in the ' zwAllGlobals module in the WZFRMRPT.MDA file. Dim DevString As zwtDevModeStr Dim DM As zwtDeviceMode 'Constants for the Fields member. Const DM_PAPERSIZE = &H2 Const DM_PAPERLENGTH = &H4 Const DM_PAPERWIDTH = &H8 Dim DevModeExtra As String Dim rpt As Report Dim response Dim msg As String 'Open the report in Design view. DoCmd.OpenReport rptName, A_DESIGN 'DoCmd OpenReport rptName, A_DESIGN (in Microsoft Access 2.0) Set rpt = Reports(rptName) If Not IsNull(rpt.PrtDevMode) Then 'Copy the PrtDevMode property to a string. DevModeExtra = rpt.PrtDevMode DevString.rgb = DevModeExtra LSet DM = DevString 'Check for the custom page size. If DM.dmPaperSize = 256 Then 'Display the custom page size. msg = "The Custom Page Size is " & DM.dmPaperWidth / 254 msg = msg & " inches wide by " & DM.dmPaperLength / 254 msg = msg & " inches long. Change the size?" response = MsgBox(msg, 4) Else msg = "The report does not have a custom page. " msg = msg & " Do you want to define one?" response = MsgBox(msg, 4) End If     If response = 6 Then 'User chose Yes; change the size. 'Initialize the Fields member. DM.dmFields = DM.dmFields Or DM_PAPERSIZE Or DM_PAPERLENGTH Or DM_PAPERWIDTH 'Set the page size. DM.dmPaperSize = 256 msg = "Please enter Page Length in inches" DM.dmPaperLength = InputBox(msg) * 254 msg = "Please enter Page Width in inches" DM.dmPaperWidth = InputBox(msg) * 254 'Update the first 68 bytes of the PrtDevMode property. LSet DevString = DM        Mid$(DevModeExtra, 1, 68) = DevString.rgb rpt.PrtDevMode = DevModeExtra End If  End If End Sub  On the View menu, click Immediate Window. Type the following line in the Immediate window

CheckCustomPage "Products by Category"

and press ENTER.

Notice that the report opens in Design view, the custom page size (if it exists) is displayed, and you are prompted to change it if you want.</li></ol>

<div class="references_section">