ACC2: Using Access Basic Code to Collate and Print Two ReportsID: Q132241
|
This article describes a method that you can use to collate and print two
reports. This method alternates two reports between the DoCmd SelectObject
and DoCmd Print macro actions.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information about Access Basic, please
refer to the "Building Applications" manual.
NOTE: This article explains a technique demonstrated in the sample
files, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0)
and RptSmp97.exe (for Microsoft Access 97). For information about how
to obtain these sample files, please see the following articles in the
Microsoft Knowledge Base:
Q145777 ACC95: Microsoft Access Sample Reports Available on MSL
Q175072 ACC97: Microsoft Access 97 Sample Reports Available on MSL
At times, you may want to print page 1 of one report and then collate that
page with page 1 of another report. Opening the reports and printing each
page individually requires the underlying query to run each time. An
alternative method is to incorporate both reports in a main/sub report.
To collate and print two reports and to test the results, follow these
steps:
'****************************************************************
'Declarations section of the module
'****************************************************************
Option Compare Database
Option Explicit
'**********************************************************************
'NumPages is the number of pages in the largest report. If one report
'has fewer pages, the DoCmd Print statement for the smaller report runs
'correctly and no additional pages are printed.
'**********************************************************************
Function CollateReports(NumPages, Rpt1 as String, Rpt2 as String)
Dim MyPageNum As Integer
' Set the page number loop and alternate printing the report pages.
For MyPageNum = 1 to NumPages
' NumPages is the number of pages to print.
DoCmd SelectObject A_REPORT, Rpt1, True
DoCmd Print A_PAGES, MyPageNum, MyPageNum
DoCmd SelectObject A_REPORT, Rpt2, True
DoCmd Print A_PAGES, MyPageNum, MyPageNum
Next MyPageNum
End Function
Microsoft Access "Language Reference," version 2.0, "Print Action," pages
375-376
Microsoft Access "Language Reference," version 2.0, "SelectObject Action,"
pages 431-432
Keywords : kbprint PtrOpt
Version : 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 23, 1999