Reports: Page Totals

        0 votes: *****     3,859 views      No comments
by Allen Browne, 20 April 2005    (for Access v2+)

Microsoft Access Tips for Serious Users

Provided by Allen Browne, allenbrowne.com


Reports: Page Totals

Each section of a report has a Format event, where you can alter properties such as Visible, Color, Size, etc in a manner similar to the Current in a form. (See Runtime Properties: Forms for details.) For example to force a page break when certain conditions are met, include a PageBreak control in the Detail Section and toggle its Visible property. In addition, the Print event can be used to perform tasks like adding the current record to a running total.

You have an Amount field, and want to display the Amount total for that page in the Page Footer. Totals are not normally available in the Page Footer, but the task requires just four lines of code!

  1. In the PageHeader's Format event procedure, add:
        curTotal = 0             'Reset the sum to zero each new Page.
  2. In the DetailSection's Print event, add:
        If PrintCount = 1 Then curTotal = curTotal + Me.Amount
  3. Place an unbound control called PageTotal in the Page Footer. In the PageFooter's Format, add:
        Me.PageTotal = curTotal
  4. In the Code Window under Declarations enter:
        Option Explicit          'Optional, but recommended for every module.
        Dim curTotal As Currency 'Variable to sum [Amount] over a Page.

That's it!


Home Index of tips Top

Rate this article:  Your rating: PoorYour rating: Not so goodYour rating: AverageYour rating: GoodYour rating: Excellent


This is a cached tutorial, reproduced with permission.

Have your say - comment on this article.

What did you think of 'Reports: Page Totals'?

No comments yet.

Why not be the first to comment on this article?!

Have your say...

Name
E-mail (e-mail address will be kept private)
Comments


Comments require approval before being displayed on this page (allow 24 hours).