Microsoft KB Archive/325237

= How to use DSum to create a running sum on a form in Access 2002 =

Article ID: 325237

Article Last Modified on 8/2/2004

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q325237





For a Microsoft Access 97 version of this article, see 103183.

For a Microsoft Access 2000 version of this article, see 210495.

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).

IN THIS TASK
SUMMARY
 * Example of a Running Sum



SUMMARY
Reports have a RunningSum property. Forms do not have a RunningSum property. This article describes how to create a running sum on a form.

back to the top

Example of a Running Sum
To create a running sum on a form, the underlying table or query must have a unique and a sequential ID field, such as an AutoNumber or a Date/Time time stamp field. If your table does not have such a field, you can open the table in Design view and then add a new field to create one.

The following example uses the sample database Northwind.mdb to show you how to create a text box on a form that sums the freight amount for the current customer order and all earlier customer orders:  Start Microsoft Access and open the sample database Northwind.mdb.  Create the following new form based on the Orders table.

NOTE: To improve readability, the underscore (_) is used in the following example as a line-continuation character. Remove the underscore from the end of the line when you are re-creating this example.

     Form:  Form1 RecordSource: Orders

Text Box: Order ID        ControlSource: OrderID Text Box: Total ControlSource: =DSum(&quot;[Freight]&quot;,&quot;Orders&quot;,_                             &quot;[OrderID] <= Forms![Form1]![OrderID]&quot;) The DSum function calculates the sum of all freight charges on orders with an Order number less than or equal to the order number that currently appears. For this reason, you must have a unique and a sequential ID field.  View the form in Form view. Note that the Total text box accumulates total freight charges for each order as you move from record to record.

back to the top

Additional query words: inf subtotal query DSum running total sum

Keywords: kbhowto kbfunctions KB325237

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.