In Access 2002 use the Printer Object
OR
Access97 (Also works in Access 2002) use PrtDevNames
Careful with the Line Wraps
'---------------------START-----------------------------------------
' Author: Jose Hernandez
Option Compare Database
Option Explicit
Type PrtDevNameStr 'See PrtDevNames property in Help
RGB As String * 104
End Type
Type PrtDevModeStr 'See PrtDevMode property in Help
RGB As String * 68
End Type
Type udtAccPrinterDEV 'Printer info from Reports
Source As String
DevName As PrtDevNameStr
DevMode As PrtDevModeStr
End Type
Private Function GetPrinterInfoEX(ByVal strSrc As String) As
udtAccPrinterDEV
On Error GoTo Proc_Error
'PURPOSE: Get DevNames & DevMode for access report
'strSrc = name of report with the printer settings.
DoCmd.OpenReport strSrc, acDesign 'Open color settings report
With GetPrinterInfoEX
.DevName.RGB = Reports(strSrc).PrtDevNames 'Get DevNames Structure
.DevMode.RGB = Reports(strSrc).PrtDevMode 'Get DevNames Structure
.Source = strSrc
End With
DoCmd.Close acReport, strSrc, acSaveNo
Proc_Exit:
If IsReportLoaded(strSrc) = True Then DoCmd.Close acReport, strSrc,
acSaveNo
Exit Function
Proc_Error:
MsgBox Err.Description
Resume Proc_Exit
End Function
Function IsReportLoaded(ByVal strReport As String) As Integer
' Returns True if the specified report is loaded.
IsReportLoaded = CBool(SysCmd(acSysCmdGetObjectState, acReport,
strReport) <> 0)
End Function
Function Print2AnyPrinter(strReport As String, strFilter As String,
strPrinterSettings As String) As Long
On Error GoTo Proc_Error
'Returns: 0 = Success!
'strReport = Report you want to print
'strFilter = Your Filter If you do not have one then pass "" as the value
'strPrinterSettings = The Report that has the printer settings! (Create a
new report and Set its Default Printer.)
'ISSUES: The reports MUST be opened in Design View on order to set the
PrtDevNames!
Dim udtPrinterDEV As udtAccPrinterDEV
Dim lngRetVal As Long
udtPrinterDEV = GetPrinterInfoEX(strPrinterSettings)
DoCmd.OpenReport strReport, acViewDesign
Reports(strReport).PrtDevNames = udtPrinterDEV.DevName.RGB
If Len(strFilter & "") > 0 Then
Reports(strReport).FilterOn = True
Reports(strReport).Filter = strFilter
End If
DoCmd.OpenReport strReport, acViewPreview
DoCmd.PrintOut acPrintAll 'Print Report
Proc_Exit:
If IsReportLoaded(strReport) = True Then DoCmd.Close acReport,
strReport, acSaveNo
Exit Function
Proc_Error:
MsgBox Err.Description
Print2AnyPrinter = Err.Number
Resume Proc_Exit
End Function
'-------------------------------END-------------------------------------
HTH
Jose