Changing the paper size on a report (1 Viewer)

TJBernard

Registered User.
Local time
Today, 09:30
Joined
Mar 28, 2002
Messages
176
Is it possible to change the paper size (from the default of 8 1/2 x 11 to Legal size 8 1/2 14) through code on MS Access. I have found how to change the printer, but not the size of the paper, which can manual be changed under File -> Page Setup

Thank you,

T.J.
 

TJBernard

Registered User.
Local time
Today, 09:30
Joined
Mar 28, 2002
Messages
176
Thank you very much, that article was helpful in my efforts of formatting a page through code.
 

MStCyr

New member
Local time
Today, 04:30
Joined
Sep 18, 2003
Messages
333
FYI . here is the Q129748 article.

Maurice


When you use the PrtDevMode property, keep the following printer driver
characteristics in mind:

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

- 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:

1. 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

dmDriver Version 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

2. 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, A_DESIGN
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

3. 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.
 

Users who are viewing this thread

Top Bottom