?
Solved

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

Posted on 2002-06-10
6
Medium Priority
?
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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