PrtDevMode Property Example

The following example uses the PrtDevMode property to check the user-defined page size for a report:

Type str_DEVMODE
    RGB As String * 94
End Type

Type type_DEVMODE
    strDeviceName As String * 16
    intSpecVersion As Integer
    intDriverVersion As Integer
    intSize As Integer
    intDriverExtra As Integer
    lngFields As Long
    intOrientation As Integer
    intPaperSize As Integer
    intPaperLength As Integer
    intPaperWidth As Integer
    intScale As Integer
    intCopies As Integer
    intDefaultSource As Integer
    intPrintQuality As Integer
    intColor As Integer
    intDuplex As Integer
    intResolution As Integer
    intTTOption As Integer
    intCollate As Integer
    strFormName As String * 16
    lngPad As Long
    lngBits As Long
    lngPW As Long
    lngPH As Long
    lngDFI As Long
    lngDFr As Long
End Type

Sub CheckCustomPage(rptName As String)
    Dim DevString As str_DEVMODE
    Dim DM As type_DEVMODE
    Dim strDevModeExtra As String
    Dim rpt As Report
    Dim intResponse As Integer
    ' Opens report in Design view.
    DoCmd.OpenReport rptName, acDesign
    Set rpt = Reports(rptName)
    If Not IsNull(rpt.PrtDevMode) Then
        strDevModeExtra = rpt.PrtDevMode   
        ' Gets current DEVMODE structure.
        DevString.RGB = strDevModeExtra
        LSet DM = DevString
        If DM.intPaperSize = 256 Then
            ' Display user-defined size.
            intResponse = MsgBox("The current " _
                & "custom page size is " _
                & DM.intPaperWidth / 254 _
                 & " inches wide by " _
                & DM.intPaperLength / 254 _
                 & " inches long. Do you want " _
                & "to change the settings?", 4)
        Else
            ' Currently not user-defined.
            intResponse = MsgBox("The report " _
                & "does not have a custom page " _
                & "size. " _
                & "Do you want to define one?", 4)
        End If
        If intResponse = 6 Then
            ' User wants to change settings.
            ' Initialize fields.
            DM.lngFields = DM.lngFields Or _
             DM.intPaperSize Or DM.intPaperLength _
                Or DM.intPaperWidth
            DM.intPaperSize = 256    ' Set custom page.
            ' Prompt for length and width.
            DM.intPaperLength =_
             InputBox("Please enter page length " _
                & "in inches.") * 254
            DM.intPaperWidth =_
             InputBox("Please enter page width " _
                & "in inches.") * 254
            LSet DevString = DM        ' Update property.
            Mid(strDevModeExtra, 1, 94) = DevString.RGB
            rpt.PrtDevMode = strDevModeExtra
        End If
    End If
End Sub

The following example shows how to change the orientation of the report. This example will switch the orientation from portrait to landscape or landscape to portrait depending on the report's current orientation.

Sub SwitchOrient(strName As String)
    Const DM_PORTRAIT = 1
    Const DM_LANDSCAPE = 2
    Dim DevString As str_DEVMODE
    Dim DM As type_DEVMODE
    Dim strDevModeExtra As String
    Dim rpt As Report
    ' Opens report in Design view.
    DoCmd.OpenReport strName, acDesign
    Set rpt = Reports(strName)
    If Not IsNull(rpt.PrtDevMode) Then
        strDevModeExtra = rpt.PrtDevMode
        DevString.RGB = strDevModeExtra
        LSet DM = DevString
        DM.lngFields = DM.lngFields Or _
             DM.intOrientation    ' Initialize fields.
        If DM.intOrientation = DM_PORTRAIT Then
            DM.intOrientation = DM_LANDSCAPE
        Else
            DM.intOrientation = DM_PORTRAIT
        End If
        LSet DevString = DM            ' Update property.
        Mid(strDevModeExtra, 1, 94) = DevString.RGB
        rpt.PrtDevMode = strDevModeExtra
    End If
End Sub