SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
When you use the PrtDevMode property, keep the following printer driver
characteristics in mind.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
NOTE: Visual Basic for Applications is called Access Basic in Microsoft
Access version 2.0. For more information about Access Basic, please refer
to the "Building Applications" manual.
- 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.
Follow these steps to find out if you are using a driver that supports
the Custom page size option:
- Click Start, point to Settings, and then click Printers.
- In the Printers box, right-click the printer name that represents
the printer that you are using in conjunction with this article.
Click Properties.
- In the '<Printer name>' Properties box, click the Paper tab and view
the Paper size box. If the Custom icon does not appear in the box,
you will not be able to use 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.
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 the Sub procedure, follow these steps.
NOTE: If you are using Microsoft Access 2.0 on a computer running Windows
95 or later, you will need to modify the Type statement in step 1 to read
as follows:
Type str_DevMode
RGB As String * 512
End Type
For more information about PrtDevMode settings in Windows 95 or later,
please see the following article in the Microsoft Knowledge Base:
140286
ACC2: PrtDevMode Settings Do Not Work Under Windows 95 or
Later
Sub Procedure Steps:
- Create a module and type the following lines in the Declarations
section:
Option Explicit
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
- Create the following procedure:
NOTE: In the following sample code, an underscore (_) at the end of a
line is used as a line-continuation character. Remove the underscore
from the end of the line when re-creating this code in Access Basic.
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, AcViewDesign
'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 Debug Window (or Immediate window in version
2.0), type the following line in the Debug window, and press ENTER
CheckCustomPage "<Report1>"
where <Report1> is the name of your report.
Note that the report opens in Design view, the custom page size (if it
exists) is displayed, and you are prompted to change it.