Option Compare Database
Option Explicit
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 Function ConvertToLandscape(ByVal strName As Variant, myOrient As Variant)
Dim rpt As Report
Dim strDevModeExtra As String
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
'strName = "repReportName1"
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.
DM.intOrientation = myOrient 'Landscape
LSet DevString = DM 'Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
DoCmd.Save acReport, strName
DoCmd.Close acReport, strName
End If
End Function
Public Function OpenAssignReport(ByVal repName As Variant, ByVal myOrient As Variant, _
Optional bolPrintOnly As Boolean)
Dim viewPref As VbMsgBoxResult
If Not bolPrintOnly Then
viewPref = MsgBox("Select Yes if you wish to print.", vbYesNo + vbDefaultButton2, "View or Print")
End If
Call ConvertToLandscape(repName, myOrient)
If bolPrintOnly Then viewPref = 6
Select Case viewPref
Case 6 'Yes
DoCmd.OpenReport repName, acNormal, "", ""
DoCmd.Close acReport, repName
Case Else 'No
DoCmd.OpenReport repName, acPreview, "", ""
End Select
End Function