Solved

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

Posted on 2002-06-10
6
257 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now