J
jbonacorda
Guest
How Can I Change The Print Device For A Report Using Code?
I am trying to change the print device (using PrtDev in VBA) for a report in one of my applications. I am able to change the paper size using the following sub -
Option Compare Database
Option Explicit
'*********************************************
' Author: Jim Bonacorda, MIS
' Phone: 732-721-5544 ext 3166
' E-mail: jbonacorda@sabert.com
' Created: 11/20/2002
' The purpose of this module is to manage the
' printer settings for reports in this application
'*********************************************
Const MOD_NAME$ = "Module modPrinterMgmt"
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
Sub sSwitchPaperSizeToLegal(rptName As String)
'The purpose of this sub is to set the page size
'for a report to legal
Const SUB_NAME$ = "sSwitchPaperSizeToLegal"
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
'Open report in design view.
DoCmd.OpenReport rptName, acDesign 'Open report in Design view.
Set rpt = Reports(rptName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode ' Get current DEVMODE structure.
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields Or DM.intPaperSize Or DM.intPaperLength Or DM.intPaperWidth
DM.intPaperSize = 5 'legal
DM.intPaperWidth = 8.5 * 254 '8.5 inches
DM.intPaperLength = 14 * 254 '14 inches
LSet DevString = DM 'Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
DoCmd.Close acReport, rptName, acSaveYes
End Sub
I modeled the print device code from the above sub, but I am running into trouble trying to change the printer -
Sub sSwitchToOfficePrinter(rptName As String)
'*************************************************
'The purpose of this sub is to change the printer
'for a report to the printer in the Sayreville
'Office
'*************************************************
Const SUB_NAME$ = "sSwitchToOfficePrinter"
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
'Open report in design view.
DoCmd.OpenReport rptName, acDesign 'Open report in Design view.
Set rpt = Reports(rptName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode 'Get current DEVMODE structure.
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields
DM.strDeviceName = "\\Sabert_GX110\Canon iR600-550-60 PCL" 'Printer in Sayreville office
LSet DevString = DM 'Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
DoCmd.Close acReport, rptName, acSaveYes
End Sub
Any suggestions will be appreciated.
Best regards,
Jim Bonacorda
I am trying to change the print device (using PrtDev in VBA) for a report in one of my applications. I am able to change the paper size using the following sub -
Option Compare Database
Option Explicit
'*********************************************
' Author: Jim Bonacorda, MIS
' Phone: 732-721-5544 ext 3166
' E-mail: jbonacorda@sabert.com
' Created: 11/20/2002
' The purpose of this module is to manage the
' printer settings for reports in this application
'*********************************************
Const MOD_NAME$ = "Module modPrinterMgmt"
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
Sub sSwitchPaperSizeToLegal(rptName As String)
'The purpose of this sub is to set the page size
'for a report to legal
Const SUB_NAME$ = "sSwitchPaperSizeToLegal"
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
'Open report in design view.
DoCmd.OpenReport rptName, acDesign 'Open report in Design view.
Set rpt = Reports(rptName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode ' Get current DEVMODE structure.
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields Or DM.intPaperSize Or DM.intPaperLength Or DM.intPaperWidth
DM.intPaperSize = 5 'legal
DM.intPaperWidth = 8.5 * 254 '8.5 inches
DM.intPaperLength = 14 * 254 '14 inches
LSet DevString = DM 'Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
DoCmd.Close acReport, rptName, acSaveYes
End Sub
I modeled the print device code from the above sub, but I am running into trouble trying to change the printer -
Sub sSwitchToOfficePrinter(rptName As String)
'*************************************************
'The purpose of this sub is to change the printer
'for a report to the printer in the Sayreville
'Office
'*************************************************
Const SUB_NAME$ = "sSwitchToOfficePrinter"
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
'Open report in design view.
DoCmd.OpenReport rptName, acDesign 'Open report in Design view.
Set rpt = Reports(rptName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode 'Get current DEVMODE structure.
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields
DM.strDeviceName = "\\Sabert_GX110\Canon iR600-550-60 PCL" 'Printer in Sayreville office
LSet DevString = DM 'Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
DoCmd.Close acReport, rptName, acSaveYes
End Sub
Any suggestions will be appreciated.
Best regards,
Jim Bonacorda
Last edited: