Solved

Set page size and orientation on a report by code

Posted on 2001-09-06
15
419 Views
Last Modified: 2008-02-01
I need to set the page size of an access report by code.


Thanks
0
Comment
Question by:earzani
  • 6
  • 5
  • 2
  • +2
15 Comments
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6461457
Here's a link.  I'll try to summarize it for you in a minute:

http://www.microsoft.com/AccessDev/Articles/GetzCh10.HTM
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6461462
Microsoft has a KB Article (Q129748) which explains how:

http://support.microsoft.com/support/kb/articles/Q129/7/48.asp


-Dennis Borg
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6461487
Option Explicit

Const glrcDeviceNameLen = 32
Const glrcFormNameLen = 32
' This is an arbitrary value. Based on experience,
' it ought to be large enough.
Const glrcExtraSize = 1024
' Structure for prtDevMode
Type glr_tagDevMode
    strDeviceName(1 To glrcDeviceNameLen) As Byte
    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
    intYResolution As Integer
    intTTOption As Integer
    intCollate As Integer
    strFormName(1 To glrcFormNameLen) As Byte
    intLogPixels As Integer
    lngBitsPerPixel As Long
    lngPelsWidth As Long
    lngPelsHeight As Long
    lngDisplayFlags As Long
    lngDisplayFrequency As Long
    lngICMMethod As Long
    lngICMIntent As Long
    lngMediaType As Long
    lngDitherType As Long
    lngICCManufacturer As Long
    lngICCModel As Long
    bytDriverExtra(1 To glrcExtraSize) As Byte
End Type
' Structure for prtDevNames
Type glr_tagDevNames
    intDriverPos As Integer
    intDevicePos As Integer
    intOutputPos As Integer
    intDefault As Integer
End Type
' Structure for prtMip
Type glr_tagMarginInfo
    lngLeft As Long
    lngTop As Long
    lngRight As Long
    lngBottom As Long
    lngDataOnly As Long
    lngWidth As Long
    lngHeight As Long
    lngDefaultSize As Long
    lngItemsAcross As Long
    lngColumnSpacing As Long
    lngRowSpacing As Long
    lngItemLayout As Long
    lngFastPrinting As Long
    lngDataSheet As Long
End Type

Public Sub SetReportSize(ByRef ReportToEdit As Report, ByVal NewWidth As Integer, ByVal NewLength As Integer)

    Dim dm As glr_tagDevMode
    Dim dmStr As glr_tagDevModeStr
    dmStr.strDevMode = ReportToEdit.PrtDevMode
    LSet dm = dmStr
    dm.intPaperSize = 256  'could also be 0
    dm.intPaperLength = NewLength
    dm.intPaperWidth = NewWidth
    dm.lngFields = dm.lngFields Or glrcDMPaperSize Or glrcDMPaperLength Or glrcDMPaperWidth
    LSet dmStr = dm
    ReportToEdit.PrtDevMode = dmStr.strDevMode
    Set ReportToEdit = Nothing
End Sub


this is an import exerpt from the article:

An Important Reminder
Remember, all the properties mentioned in this section (prtDevMode, prtDevNames, and prtMip) are available only in Design view. You must make sure your report or form is open in Design view before attempting to set any of these properties. (You can retrieve the properties, of course, no matter what the mode.)

Changing Paper Size
Contrary to the information presented above, many printers do not allow you to specify a user-defined page size. In addition, some printers use a page size of 0 to indicate a user-defined size, and some use 256. You need to retrieve information about the specific printer (see the section "Retrieving Printer Capabilities" later in this chapter for information on this) before trying to set a specific nonstandard page size.

hope this helps - cjswimmer
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 9

Expert Comment

by:ornicar
ID: 6461673
Listening.
0
 

Author Comment

by:earzani
ID: 6461703
Thanx folks.

I'll try it soon and i'll get back to pay my debts !
I don't need to set a custom size paper, just Legal or Letter, i suppose there's some special value to be assigned to dmPaperSize in order to select one or another.

PS: Please excuse my poor english.
0
 

Author Comment

by:earzani
ID: 6461707
Thanx folks.

I'll try it soon and i'll get back to pay my debts !
I don't need to set a custom size paper, just Legal or Letter, i suppose there's some special value to be assigned to dmPaperSize in order to select one or another.

PS: Please excuse my poor english.
0
 

Author Comment

by:earzani
ID: 6461711
Thanx folks.

I'll try it soon and i'll get back to pay my debts !
I don't need to set a custom size paper, just Legal or Letter, i suppose there's some special value to be assigned to dmPaperSize in order to select one or another.

PS: Please excuse my poor english.
0
 
LVL 6

Accepted Solution

by:
cjswimmer earned 100 total points
ID: 6461724
ok you can just replace the function section in my post with:

Public Sub SetReportSize(ByRef ReportToEdit As Report, ByVal SizeID as Long)
   Dim dm As glr_tagDevMode
   Dim dmStr As glr_tagDevModeStr
   dmStr.strDevMode = ReportToEdit.PrtDevMode
   LSet dm = dmStr
   dm.intPaperSize = SizeID  'could also be 0
   dm.lngFields = dm.lngFields Or glrcDMPaperSize
   LSet dmStr = dm
   ReportToEdit.PrtDevMode = dmStr.strDevMode
   Set ReportToEdit = Nothing
End Sub

here is a list of the possible values you could pass it and what they represent:

1   Letter (8.5 x 11 in.)
2   Letter Small (8.5 x 11 in.)
3   Tabloid (11 x 17 in.)
4   Ledger (17 x 11 in.)
5   Legal (8.5 x 14 in.)
6   Statement (5.5 x 8.5 in.)
7   Executive (7.25 x 10.5 in.)
8   A3 (297 x 420 mm)
9   A4 (210 x 297 mm)
10  A4 Small (210 x 297 mm)
11  A5 (148 x 210 mm)
12  B4 (250 x 354)
13  B5 (182 x 257 mm)
14  Folio (8.5 x 13 in.)
15  Quarto (215 x 275 mm)
16  11 x 17 in.
18  Note (8.5 x 11 in.)
19  Envelope #9 (3.875 x 8.875 in.)
20  Envelope #10 (4.125 x 9.5 in.)
21  Envelope #11 (4.5 x 10.375 in.)
22  Envelope #12 (4.25 x 11 in.)
23  Envelope #14 (5 x 11.5 in.)
24  C size sheet
25  D size sheet
26  E size sheet
27  Envelope DL (110 x 220 mm)
28  Envelope C5 (162 x 229 mm)
29  Envelope C3 (324 x 458 mm)
30  Envelope C4 (229 x 324 mm)
31  Envelope C6 (114 x 162 mm)
32  Envelope C65 (114 x 229 mm)
33  Envelope B4 (250 x 353 mm)
34  Envelope B5 (176 x 250 mm)
35  Envelope B6 (176 x 125 mm)
36  Envelope (110 x 230 mm)
37  Envelope Monarch (3.875 x 7.5 in.)
38  6-3/4 Envelope (3.625 x 6.5 in.)
39  US Std Fanfold (14.875 x 11 in.)
40  German Std Fanfold (8.5 x 12 in.)
41  German Legal Fanfold (8.5 x 13 in.)
256 User-defined

you still need to include the declaration sections from my previous post
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6461735
earzani, don't use you're browser's refresh button to reload this page - it duplicates your last post.  Use the link up at the upper right side of this page that says "Reload Question" to refresh the page.
0
 

Author Comment

by:earzani
ID: 6461828
Thanx folks.

I'll try it soon and i'll get back to pay my debts !
I don't need to set a custom size paper, just Legal or Letter, i suppose there's some special value to be assigned to dmPaperSize in order to select one or another.

PS: Please excuse my poor english.
0
 

Author Comment

by:earzani
ID: 6462337
cjswimmer,
Just a little detail:
how can I use it on run time ?
I mean, can I open a report, set the page type and then show it or print it without seeing the report in design mode ?

Anyway you'll get the points !
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6470809
you can use:
   DoCmd.Echo False
to stop screen repainting while you edit the report.  Just don't forget to turn it back on when you're done.



0
 

Expert Comment

by:phillystyle123
ID: 8253398
i'm really new to access can someone explain exactly how this works?

?: i created a module with the code in this post.  how do i tell my report to use the module?  if it's on click from a command button - i've got a command btn printing out the report now based on my filter.  c

? : where do i put the values:
eg: Letter (8.5 x 11 in.) in the function

Public Sub SetReportSize(ByRef ReportToEdit As Report, ByVal SizeID as Long)
  Dim dm As glr_tagDevMode
  Dim dmStr As glr_tagDevModeStr
  dmStr.strDevMode = ReportToEdit.PrtDevMode
  LSet dm = dmStr
  dm.intPaperSize = SizeID  'could also be 0
  dm.lngFields = dm.lngFields Or glrcDMPaperSize
  LSet dmStr = dm
  ReportToEdit.PrtDevMode = dmStr.strDevMode
  Set ReportToEdit = Nothing
End Sub

0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 8253956
It would be appropriate to post a new thread with these questions.  Just include a reference to this thread in your own question.
0
 

Expert Comment

by:phillystyle123
ID: 8254166
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

809 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