This article shows you how to can create a running total for each page of a report.
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:
- Open the report in Design view.
- On the View menu, click Code.
- Type the following lines in the Declarations
Option Compare Database
Public PageSum as Double
- 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:
Private Sub Detail_Print(Cancel As Integer, FormatCount As Integer)
PageSum = PageSum + Reports![<report name>]![<field name>]
- Enter the following code in the event procedure for the Format property of the page header:
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
' reset the counter for each new page
PageSum = 0
- Insert a text box control with the following properties in the page footer:
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.
Article ID: 216311 - Last Review: October 11, 2006 - Revision: 1.3
- Microsoft Access 2000 Standard Edition
|kbhowto kbprogramming KB216311|