OleAutoPrint




'PrintReport MyDBPath, MyReportName, acPreview, MyCriteria


Sub PrintReport(ByVal DBPath As String, ByVal ReportName _
As String
Optional OpenMode As Integer, Optional Filter As String, _
Optional
Criteria As String)
Dim appAccess As Object
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase (DBPath)
'********************************************************

'Access constants for OpenMode are

'acNormal - Print (default)

'acPreview - Print Preview

'acDesign - Design Edit Mode

'********************************************************

appAccess.DoCmd.OpenReport ReportName, OpenMode, _
FilterName
Criteria
'********************************************************

'if open mode is Preview then don't quit Access this can

'also be deleted if you do not want Access to quit after

'printing a report

'********************************************************

If OpenMode <> acPreview Then
appAccess.Quit
End If
Set appAccess = Nothing
End Sub

You can print canned reports in an Access database from VB in
different ways. I created this routine to print any report
with any criteria or filter from any database. It opens Access
with the user- or program-controlled database, then opens the
report in the mode specified. In order for this to work with
Access constants, you must select Access from the References
dialog box (accessed from References under the Tools menu in
VB4 and under the Project menu in VB5). The PrintReport
subroutine has the same parameters as the Access
Docmd.OpenReport command with the exception of DBPath.
I didn't use IsMissing to test for missing parameters because
Access handles it for you, but you can add it to supply your
own default values for any missing parameters. Note: In VB4,
any optional parameter must be a Variant data type. When you
want to print a report from code, call the routine like this:










( oleautoprint.html )- by Paolo Puglisi - Modifica del 17/12/2023