Set page size and orientation on a report by code

I need to set the page size of an access report by code.


Thanks
earzaniAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
cjswimmerConnect With a Mentor Commented:
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
 
cjswimmerCommented:
Here's a link.  I'll try to summarize it for you in a minute:

http://www.microsoft.com/AccessDev/Articles/GetzCh10.HTM
0
 
DennisBorgCommented:
Microsoft has a KB Article (Q129748) which explains how:

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


-Dennis Borg
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
cjswimmerCommented:
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
 
ornicarCommented:
Listening.
0
 
earzaniAuthor Commented:
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
 
earzaniAuthor Commented:
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
 
earzaniAuthor Commented:
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
 
cjswimmerCommented:
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
 
earzaniAuthor Commented:
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
 
earzaniAuthor Commented:
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
 
cjswimmerCommented:
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
 
phillystyle123Commented:
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
 
cjswimmerCommented:
It would be appropriate to post a new thread with these questions.  Just include a reference to this thread in your own question.
0
 
phillystyle123Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.