Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2002-06-10
6
Medium Priority
?
270 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

564 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