Link to home
Start Free TrialLog in
Avatar of earzani
earzani

asked on

Set page size and orientation on a report by code

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


Thanks
Avatar of cjswimmer
cjswimmer

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

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

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


-Dennis Borg
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
Avatar of earzani

ASKER

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.
Avatar of earzani

ASKER

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.
Avatar of earzani

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of cjswimmer
cjswimmer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of earzani

ASKER

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.
Avatar of earzani

ASKER

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 !
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.



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

It would be appropriate to post a new thread with these questions.  Just include a reference to this thread in your own question.