ACC2000: How to Create Page Totals on a Report

ID: Q216311


The information in this article applies to:
  • Microsoft Access 2000

Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).


SUMMARY

This article shows you how to can create a running total for each page of a report.


MORE INFORMATION

You can use the RunningSum property to calculate record-by-record or group-by-group totals in a report. Such a device is not available if you want to show a total on each page.

To sum an item per page, follow these steps:

  1. Open the report in Design view.


  2. On the View menu, click Code.


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


  4. 
    Option Compare Database
    Option Explicit
    Public PageSum as Double 
  5. Enter the following code in the event procedure for the Print property of the detail section where <report name> is the name of your report, and <field name> is the name of the field you want to sum:


  6. 
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
       PageSum  = PageSum + Reports![<report name>]![<field name>] 
    End Sub 
  7. Enter the following code in the event procedure for the Format property of the page header:


  8. 
    Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
       ' reset the counter for each new page
       PageSum = 0 
    End Sub 
  9. Insert a text box control with the following properties in the page footer:
    
       Name: txtPageTotal
       ControlSource: =[PageSum] 
    Run the report and note that the text box displays the sum of the relevant field for each page. If you want to simulate a running sum for the report, delete the reset line from the page header Format event.


Additional query words:

Keywords : kbdta AccCon
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: May 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.