ACC2: Using Access Basic Code to Collate and Print Two Reports

Last reviewed: October 24, 1997
Article ID: Q132241
The information in this article applies to:
  • Microsoft Access version 2.0

SUMMARY

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:

   ARTICLE-ID: Q145777
   TITLE     : ACC95: Microsoft Access Sample Reports Available on MSL

   ARTICLE-ID: Q175072
   TITLE     : ACC97: Microsoft Access 97 Sample Reports Available on MSL

MORE INFORMATION

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:

  1. Open the sample database NWIND.MDB.

  2. Create a new module and type the following lines in the Declarations section:

        '****************************************************************
        'Declarations section of the module
        '****************************************************************
    

          Option Compare Database
          Option Explicit
    

  3. Type the following function:

        '**********************************************************************
        '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
    
    

  4. To test the results, type the following line in the Immediate Window, and then press ENTER:

          ? CollateReports(1, "Sales summaries", "Sales Totals by amount")
    

    Note that Microsoft Access prints one page from each report.

REFERENCES

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          : PtrOpt kbprint
Version           : 2.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.