The information in this article applies to:
- Microsoft Access version 2.0
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
This article demonstrates a sample user-defined Access Basic Sub procedure
you can use to set a report's PrtDevMode property to change the page
orientation before you print the report.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information about Access Basic, please
refer to the "Building Applications" manual.
MORE INFORMATION
When you change a report's page orientation by setting 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.
How to Change the Page Orientation
- Create a module and enter the following statement in the Declarations
section:
Option Explicit
- Enter the following procedure:
Sub ChgRptOrient (ReportName 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
'Constant for the Fields member.
Const DM_ORIENTATION = &H1
Dim stDevModeExtra As String
Dim rpt As Report
Dim msg As String
'Open the report in Design view.
DoCmd OpenReport ReportName, A_DESIGN
Set rpt = Reports(ReportName)
If Not IsNull(rpt.PrtDevMode) Then
'Copy the PrtDevMode property to a string.
stDevModeExtra = rpt.PrtDevMode
DevString.rgb = stDevModeExtra
LSet dm = DevString
'Display the current orientation.
msg = "The Orientation is currently"
If dm.dmOrientation = 1 Then
msg = msg & " Portrait. Change to Landscape?"
Else
msg = msg & " Landscape. Change to Portrait?"
End If
response = MsgBox(msg, 4)
If response = 6 Then
'User chose Yes.
'Initialize the Fields member.
dm.dmFields = dm.dmFields Or DM_ORIENTATION
'Set the orientation.
If dm.dmOrientation = 1 Then
'Set the orientation to Landscape.
dm.dmOrientation = 2
Else
'Set the orientation to Portrait.
dm.dmOrientation = 1
End If
'Update the first 68 bytes of the PrtDevMode property.
LSet DevString = dm
Mid$(stDevModeExtra, 1, 68) = DevString.rgb
rpt.PrtDevMode = stDevModeExtra
End If
End If
End Sub
- Choose Immediate Window from the View menu. Type the following line in
the Immediate window, and then press ENTER
ChgRptOrient "<Report1>"
where <Report1> is the name of your report.
The report opens in Design view, the current orientation is displayed, and
you are prompted to change the orientation.
REFERENCES
Microsoft Access "Language Reference," version 2.0, "PrtDevMode property,"
pages 484-490