Solved

Simple Code needed to set all Reports to A4 size on open

Posted on 2002-06-10
6
263 Views
Last Modified: 2011-10-03
Hi everyone,

My application consists of about 30 reports all of which are set to (and should be set to) A4 paper.  However each time I load my application on to another computer or change default  printers all of the reports revert to page set-up of " letter size" paper.

I realize that this is an access quirk.

I would much appreciate if an expert could write me simple code that would set all reports to A4 size paper every time the application is loaded.

Alternately I would equally accept a simpler solution which may, for example, involve changing some options setting to prevent the change of the report page set-up to "letter-sized".

Looking forward to your suggestions.

Many thanks.

Zak
0
Comment
Question by:zak5000
6 Comments
 
LVL 5

Expert Comment

by:funke
ID: 7068842
Here's a function that may be a little overkill but you can set your paper sizes...just call this in your form event where you choose which report to print (or you could use it in the report_open event) - you may also have to find out the constant for A4
'----------------------------------------------------

Public Function PRN_PaperSize(p_Rpt As Report, p_nSize As Long)
'This function allows us to change the size of the paper on which
'a report is set to print (1=letter, 2=legal).
On Error GoTo PRN_PaperSize_ERROR

    'Declare variables
    Const DM_LETTER = 1
    Const DM_LEGAL = 2
    Dim DevString As str_DEVMODE
    Dim DM As type_DEVMODE
    Dim DevModeExtra As String
    Dim rpt As Report
    Dim sRptNm As String
    sRptNm = p_Rpt.Name
   
    'Open the report and set PaperSize for the report's devmode
    If Not IsNull(p_Rpt.PrtDevMode) Then
        DevModeExtra = p_Rpt.PrtDevMode
        DevString.RGB = DevModeExtra
        LSet DM = DevString
        DM.dmFields = DM.dmFields Or DM_PAPERSIZE ' Initialize fields.
        If DM.dmPaperSize = IIf(p_nSize = 1, DM_LETTER, DM_LEGAL) Then
            Exit Function
        End If
    End If
    'Close the report and REOPEN it so that you can save changes to the DEVMODE
    DoCmd.Close acReport, sRptNm
    DoCmd.OpenReport sRptNm, acDesign    ' Opens report in Design view.
    Set rpt = Reports(sRptNm)
    If Not IsNull(rpt.PrtDevMode) Then
        DevModeExtra = rpt.PrtDevMode
        DevString.RGB = DevModeExtra
        LSet DM = DevString
        DM.dmFields = DM.dmFields Or DM_PAPERSIZE ' Initialize fields.
        DM.dmPaperSize = IIf(p_nSize = 1, DM_LETTER, DM_LEGAL)
        LSet DevString = DM                ' Update property.
        Mid$(DevModeExtra, 1, 94) = DevString.RGB
        rpt.PrtDevMode = DevModeExtra
        'Save report and close
        DoCmd.Save acReport, sRptNm
        DoCmd.Close acReport, sRptNm
        DoCmd.OpenReport sRptNm, acPreview
    End If

Exit Function
PRN_PaperSize_ERROR:
    Exit Function
   
End Function
0
 
LVL 5

Expert Comment

by:funke
ID: 7068848
oops - you'll need to declare these global constants too

Type str_DEVMODE
    RGB As String * 94
End Type

Type type_DEVMODE
    dmDeviceName As String * 16
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * 16
    dmPad As Long
    dmBits As Long
    dmPW As Long
    dmPH As Long
    dmDFI As Long
    dmDFr As Long
End Type

Const DM_ORIENTATION = &H1
Const DM_PAPERSIZE = &H2
Const DM_PAPERLENGTH = &H4
Const DM_PAPERWIDTH = &H8
Const DM_SCALE = &H10
Const DM_COPIES = &H100
Const DM_DEFAULTSOURCE = &H200
Const DM_PRINTQUALITY = &H400
Const DM_COLOR = &H800
Const DM_DUPLEX = &H1000
Const DM_YRESOLUTION = &H2000
Const DM_TTOPTION = &H4000
Const DM_COLLATE = &H8000
Const DM_FORMNAME = &H10000
0
 
LVL 5

Expert Comment

by:funke
ID: 7068866
DM_A4 = 9 '(A4 - 210 x 297 mm)

You can add that to you're function or you can set the paper height and width properties
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:zak5000
ID: 7069552
funke,

Thanks for your suggestion. Although my db is quite large and complex I am a relative beginner (and used what I now consider simple code - because I learned Access on a need to know, self taught basis)and do not know how to set page-setup properties programatically.  Quite franky I don't understand very much of the code you suggested.

Failing using code that would rund each time my db is opened, check to make sure all reports are set to A4 size paper and set them all to A4 if they are not so already set. I would not mind using code that would be behind the open event of each report and would set the report to A4 each time.

I am not in the habit of asking experts to write code for me, but the fact is that my Application is complete all except for this access quirk that messes with my report page sizes.

Time is of the essence for me right now so I am not in a position to learn what your function is doing programatically. Would it be possible for you to consolidate your messages into the 'actual' code that I would in include in the open event of each report to set paper-size to A4 and separately point out any global variables that I need to include in a public module that I currently use to declare global variables.

My apologies for my lack of expetise and thanks in advance.

zak
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7230567

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
 - PAQ'd and pts refunded
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7248143
Per recommendation, points refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question