ACC2: Using the PrtDevMode Property to Change Page Orientation

ID: Q129722


The information in this article applies to:


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:

How to Change the Page Orientation


  1. Create a module and enter the following statement in the Declarations section:
    
          Option Explicit 


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


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


Keywords          : kbprint PtrSetup 
Version           : 2.0
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: April 9, 1999