Change report size programmatically.
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
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