Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 17th, 2004, 12:15 PM
Authorized User
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need to set paper orientation and size in code

I want to set the orientation of a report to landscape and the paper size of the report to Legal in code. Is it possible? Thank you for your help.

Mark J. Weisberger
Mark J. Weisberger
Old September 20th, 2004, 12:10 AM
Friend of Wrox
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc

Here is a KB article that explains how:

ACC2000: How to Build a Visual Basic Module to Print a Report in Landscape Mode on Legal-Size Paper
View products that this article applies to.
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).

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.
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("<report name>")
DoCmd.OpenReport "<report name>", acViewPreview

Similar Threads
Thread Thread Starter Forum Replies Last Post
Set Paper Size (custom also) to default Printer gaurikhot .NET Framework 2.0 2 December 6th, 2008 01:50 AM
Problem with custom paper size adrineh Crystal Reports 0 August 26th, 2006 03:21 AM
how to set the paper size in javascript sundarisekaran J2EE 1 July 15th, 2004 04:42 PM
report size according to A4 paper haahoou VB Databases Basics 1 January 25th, 2004 05:05 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.