SE081398
asked on
not understanding prtdevmode example
I would like to change the papersize of the report from 8.5 X 11 to 6X4 . I've used the following example and I don't seem to understand it.
when I run this example and select change paper size the inputboxes come up for width and length. then the report tries to open and the error
"there was a problem retrieving printer information for the HP printer. the object may have been sent to a printer that is unavailable."
What is going on and how do I change the size of the report in code?
Option Explicit
Type zwtDevModeStr
RGB As String * 94
End Type
Type zwtDeviceMode
dmDeviceName As String * 16
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperlength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * 16
dmPad As Long
dmBits As Long
dmPW As Long
dmDFI As Long
dmDRr As Long
End Type
Sub CheckCustomPage(rptName As String)
' The zwtDevModeStr and zwtDeviceMode types are defined in the
' zwAllGlobals module in the WZFRMRPT.MDA file.
Dim DevString As zwtDevModeStr
Dim DM As zwtDeviceMode
'Constants for the Fields member.
Const DM_PAPERSIZE = &H2
Const DM_PAPERLENGTH = &H4
Const DM_PAPERWIDTH = &H8
Dim DevModeExtra As String
Dim rpt As Report
Dim response
Dim msg As String
'Open the report in Design view.
DoCmd.OpenReport rptName, acViewDesign
'DoCmd OpenReport rptName, A_DESIGN (in Microsoft Access 2.0)
Set rpt = Reports(rptName)
If Not IsNull(rpt.PrtDevMode) Then
'Copy the PrtDevMode property to a string.
DevModeExtra = rpt.PrtDevMode
DevString.RGB = DevModeExtra
LSet DM = DevString
'Check for the custom page size.
If DM.dmPaperSize = 256 Then
'Display the custom page size.
msg = "The Custom Page Size is " & DM.dmPaperWidth / 254
msg = msg & " inches wide by " & DM.dmPaperlength / 254
msg = msg & " inches long. Change the size?"
response = MsgBox(msg, 4)
Else
msg = "The report does not have a custom page. "
msg = msg & " Do you want to define one?"
response = MsgBox(msg, 4)
End If
If response = 6 Then
'User chose Yes; change the size.
'Initialize the Fields member.
DM.dmFields = DM.dmFields Or DM_PAPERSIZE Or _
DM_PAPERLENGTH Or DM_PAPERWIDTH
'Set the page size.
DM.dmPaperSize = 256
msg = "Please enter Page Length in inches"
DM.dmPaperlength = InputBox(msg) * 254
msg = "Please enter Page Width in inches"
DM.dmPaperWidth = InputBox(msg) * 254
'Update the first 68 bytes of the PrtDevMode property.
LSet DevString = DM
Mid$(DevModeExtra, 1, 68) = DevString.RGB
rpt.PrtDevMode = DevModeExtra
End If
End If
End Sub
when I run this example and select change paper size the inputboxes come up for width and length. then the report tries to open and the error
"there was a problem retrieving printer information for the HP printer. the object may have been sent to a printer that is unavailable."
What is going on and how do I change the size of the report in code?
Option Explicit
Type zwtDevModeStr
RGB As String * 94
End Type
Type zwtDeviceMode
dmDeviceName As String * 16
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperlength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * 16
dmPad As Long
dmBits As Long
dmPW As Long
dmDFI As Long
dmDRr As Long
End Type
Sub CheckCustomPage(rptName As String)
' The zwtDevModeStr and zwtDeviceMode types are defined in the
' zwAllGlobals module in the WZFRMRPT.MDA file.
Dim DevString As zwtDevModeStr
Dim DM As zwtDeviceMode
'Constants for the Fields member.
Const DM_PAPERSIZE = &H2
Const DM_PAPERLENGTH = &H4
Const DM_PAPERWIDTH = &H8
Dim DevModeExtra As String
Dim rpt As Report
Dim response
Dim msg As String
'Open the report in Design view.
DoCmd.OpenReport rptName, acViewDesign
'DoCmd OpenReport rptName, A_DESIGN (in Microsoft Access 2.0)
Set rpt = Reports(rptName)
If Not IsNull(rpt.PrtDevMode) Then
'Copy the PrtDevMode property to a string.
DevModeExtra = rpt.PrtDevMode
DevString.RGB = DevModeExtra
LSet DM = DevString
'Check for the custom page size.
If DM.dmPaperSize = 256 Then
'Display the custom page size.
msg = "The Custom Page Size is " & DM.dmPaperWidth / 254
msg = msg & " inches wide by " & DM.dmPaperlength / 254
msg = msg & " inches long. Change the size?"
response = MsgBox(msg, 4)
Else
msg = "The report does not have a custom page. "
msg = msg & " Do you want to define one?"
response = MsgBox(msg, 4)
End If
If response = 6 Then
'User chose Yes; change the size.
'Initialize the Fields member.
DM.dmFields = DM.dmFields Or DM_PAPERSIZE Or _
DM_PAPERLENGTH Or DM_PAPERWIDTH
'Set the page size.
DM.dmPaperSize = 256
msg = "Please enter Page Length in inches"
DM.dmPaperlength = InputBox(msg) * 254
msg = "Please enter Page Width in inches"
DM.dmPaperWidth = InputBox(msg) * 254
'Update the first 68 bytes of the PrtDevMode property.
LSet DevString = DM
Mid$(DevModeExtra, 1, 68) = DevString.RGB
rpt.PrtDevMode = DevModeExtra
End If
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh well, looks like I have to do it the non elegent way and in my case I have to create 5 copies of each report to allow for different sizes and landscape & portrait.
thanks though tuvi.