1. SwitchOrient(report_name)
This will set the orientation of report_name to Landscape ALLWAYS.
2.SwitchOrient(report_name, [DM_LANDSCAPE | DM_PORTRAIT])
This will set the orientation of report_name to either Portrait or Landscape, according to the second parameter's value (1 or 2, see the const declaration bellow).
Public Const DM_PORTRAIT = 1
Public Const DM_LANDSCAPE = 2
Type str_DEVMODE
RGB As String * 94
End Type
Type type_DEVMODE
strDeviceName As String * 16
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
intResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName As String * 16
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type
Public Sub SwitchOrient(strName As String, Optional ToOrient As Byte = DM_LANDSCAPE)
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
DoCmd.OpenReport strName, acDesign ' Opens report in Design view.
Set rpt = Reports(strName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields Or DM.intOrientation ' Initialize fields.
If DM.intOrientation <> ToOrient Then
DM.intOrientation = ToOrient
End If
LSet DevString = DM ' Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
'----- To Close & Save the Report
DoCmd.Close acReport, strName, acSaveYes 'Close and save
End Sub