To create running totals using a formula

  1. Create a report using the sample data, Xtreme.mdb. Link the Customers and Orders tables and place the following fields from left to right in the Details section:
    {customer.CUSTOMER NAME}
    {orders.ORDER ID}
    {orders.ORDER AMOUNT}
  2. On the View menu, click Field Explorer.
  3. Select Formula Fields in the Field Explorer dialog box and click New.
  4. Name the formula "RunningTotal" and click Use Editor.

    The Formula Workshop appears with Formula Editor active.

  5. Enter the following into the Formula box:
    WhilePrintingRecords;
    CurrencyVar Amount;
    Amount := Amount + {Orders.Order Amount};
  6. Click the Save and close button on the Formula Workshop.
  7. Place this formula in the Details section of your report, just to the right of the Orders.Order Amount field.

    This formula prints the running total of the values in the Order Amount field.

  8. On the Insert menu, click Group and group the report on the Customer.Customer Name field.
  9. In the Formula Workshop, create "AmountReset":
    WhilePrintingRecords;
    CurrencyVar Amount := 0;

    This formula says:

    Set the value in the Amount variable to 0.

  10. Place this formula in the Group Header #1 section of your report.

    Because the Group Header #1 section appears once for every group, @AmountReset will execute each time the group changes. Thus, the Amount variable is reset to 0 each time a new group begins.

  11. Select the @AmountReset formula on the report and use the Format Editor to suppress it so that it will not appear in the final print-out.
  12. In the Formula Workshop, create "AmountDisplay":
    WhilePrintingRecords;
    CurrencyVar Amount;

    This formula simply displays the current value of the Amount variable at any time.

  13. Place this formula in the Group Footer #1 section of your report.

    Because the Group Footer #1 section appears once for every group, @AmountDisplay will execute each time a group ends. Thus, the value stored in the Amount variable will be printed each time the group changes.



    On your report, each row in the running total column displays the current record value added to the previous values. The running total starts fresh with each new group, and the final running total for each group becomes the subtotal for that group.