'---------------------------------------------------------------------- 'Description 'This procedure prints or previews a report, and then closes the current 'instance of Microsoft Access (because objAccess is a procedure-level 'variable). 'Date 26/09/2001 AC 'Example PrintAccessReport dbname:= _ ' "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", ' rptname:="Sales by Category", preview:=True 'Called .... 'Master at www.ssw.com.au/ssw/kb/CodeBase '---------------------------------------------------------------------- Sub PrintAccessReport(dbname As String, rptname As String, preview As Boolean) Dim objAccess As Object On Error GoTo PrintAccessReport_ErrHandler Set objAccess = CreateObject("Access.Application") With objAccess .OpenCurrentDatabase filepath:=dbname If preview Then 'Preview report on screen. .Visible = True .DoCmd.OpenReport reportname:=rptname, view:=Access.acPreview Else 'Print report to printer. .DoCmd.OpenReport reportname:=rptname, view:=Access.acNormal DoEvents 'Allow report to be sent to printer. else Msgbox "Logic Error" End If End With Set objAccess = Nothing Exit Sub PrintAccessReport_ErrHandler: MsgBox Error$(), , "Print Access Report" End Sub