|
Question : Cumulative Count in a Query
|
|
I am trying to add a column to a query that will simply have a sequential count of each record. For example, the query output would look as follows:
Date Count ~~~~ ~~~~~ 1/1/03 1 1/2/03 2 1/4/03 3 1/3/03 4
|
|
Answer : Cumulative Count in a Query
|
|
You would need a code module with a function in it like this:
Public Function Counter(dField as Date) As Long Static nCounter As Long nCounter = nCounter + 1 Counter = nCounter End Function
Then your query would look like this:
SELECT Date, Counter([Date]) As Count FROM [Table]
One note: As you scroll through the query, the counter will change. It will call the function as you scroll through. You can use the query for a report and it will work fine. Also, you can update an extra field in the table with the counter and it will work fine.
Thanks!
Joe
|
|
|
|