ACC2000: How to Build a Visual Basic Module to Print a Report in Landscape Mode on Legal-Size Paper (302416)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q302416
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

This article describes how to create a Visual Basic module (PrintDevMode) to format a report so that you can print or preview the report in Landscape mode on legal-size paper. The instructions in the article include code for a command button that opens the formatted report.

MORE INFORMATION

To print or preview a report in Landscape mode on 8.5-by-14-inch (legal-size) paper, create the following module:
  1. In Access, press ALT+F11 to start the Visual Basic Editor.
  2. On the Insert menu, click Module, and then add the following code to the new module:
    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
    
    Public Function SetLegalSize(strName As String)
       Dim rpt As Report
       Dim strDevModeExtra As String
       Dim DevString As str_DEVMODE
       Dim DM As type_DEVMODE
    
    DoCmd.OpenReport strName, acDesign 'Opens report in Design view.
    
    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.
       DM.intPaperSize = 5 'Legal size
       DM.intOrientation = 2 'Landscape
       LSet DevString = DM 'Update property.
       Mid(strDevModeExtra, 1, 94) = DevString.RGB
       rpt.PrtDevMode = strDevModeExtra
       DoCmd.Save acReport, strName
       DoCmd.Close acReport, strName
    End If
    
    End Function
    					
  3. Add the following code to an On Click event for a command button:
    SetLegalSize("<report name>")
    DoCmd.OpenReport "<report name>", acViewPreview

Modification Type:MajorLast Reviewed:6/30/2004
Keywords:kbinfo kbprint KB302416