Microsoft KB Archive/302416

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

Article ID: 302416

Article Last Modified on 6/30/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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:  In Access, press ALT+F11 to start the Visual Basic Editor.  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   Add the following code to an On Click event for a command button: SetLegalSize(&quot; &quot;) DoCmd.OpenReport &quot; &quot;, acViewPreview 

Keywords: kbinfo kbprint KB302416

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.