How to set the Orientation of the report in VBA? (1 Viewer)

P

pcisec

Guest
I know how to open a report or print the report using VBA. I want to set the orientation of the report (landscape or portrait) in VBA too, but I don't know how to do it, please help. (code example is appreciated)
 

mtairhead

Registered User.
Local time
Today, 07:33
Joined
Oct 17, 2003
Messages
138
Does anyone have a solution to this? We have the same problem.
 
T

TomKelly

Guest
See VBA-Help for "PrtDevMode"

For example copy the following code:

Const glrcDeviceNameLen = 32
Const glrcFormNameLen = 32

Const glrcExtraSize = 1024 ' This is an arbitrary value. Based on experience, it ought to be large enough.
Const glrcDevnamesFixed = 8
Const glrcMaxDevice = 32

' 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

' This is the number of bytes in the fixed portion of
' the DEVMODE structure. We've just broken the
' two sizes apart in case the fixed portion of
' the structure changes.

Const glrcDevModeSize = 148
Const glrcDevModeMaxSize = glrcDevModeSize + glrcExtraSize

' Temp structure for prtDevMode info.
Type glr_tagDevModeStr
strDevMode As String * glrcDevModeMaxSize
End Type


Sub SetOrientation(sReportName As String, bPortrait As Boolean)
Dim DM As glr_tagDevMode
Dim DMStr As glr_tagDevModeStr
Application.Echo False
DoCmd.SetWarnings False
DoCmd.OpenReport sReportName, acViewDesign
DoCmd.SetWarnings True
DMStr.strDevMode = Reports(sReportName).PrtDevMode
LSet DM = DMStr
DM.intOrientation = IIf(bPortrait, 1, 2) ' 1 = Portrait / 2 = Landscape
LSet DMStr = DM
Reports(sReportName).PrtDevMode = DMStr.strDevMode
DoCmd.SetWarnings False
DoCmd.Close acReport, sReportName, acSaveYes
DoCmd.SetWarnings True
Application.Echo True
End Sub

Hope this helps.
 

Users who are viewing this thread

Top Bottom