ACC2: Using the PrtDevMode Property to Change Page OrientationID: Q129722
|
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.
When you change a report's page orientation by setting the PrtDevMode
property, keep the following printer driver characteristics in mind:
Option Explicit
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
Microsoft Access "Language Reference," version 2.0, "PrtDevMode property,"
pages 484-490
Keywords : kbprint PtrSetup
Version : 2.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: April 9, 1999