|
Question : Rank records in an Access Dbase by date
|
|
I am trying to rank my customer orders dbase - a field which shows each cutomer's 1rst order, their 2nd order, 3rd order and so on, based on the invoice dates (sorted asc). My table has 2 fields: Customer Number, Invoice Date.
Using an example shown here, http://support.microsoft.com/kb/208946 (example 1), I am able to rank ONE customer at a time (If I filter my source table to show only one specific Customer Number). However, my source table has 25000+ records with many Customer Numbers, each with between 1 and 100 Invoice Dates . . . when I try it unfiltered, it does not rank 1,2,3,4 . . . but rather something like 10, 47, 124 . . . .
Is it possible to rank all 25000+ records so that it will rank each Customer Number order 1,2,3,4 . . . and it will start over at 1 each time the Customer Number changes?
Max
|
|
Answer : Rank records in an Access Dbase by date
|
|
you will need a function to do that. place this function in a module
Function GetCount(sFieldName As String) As Long Static sCurrentField As String Static intCnt As Long If sFieldName = sCurrentField Then intCnt = intCnt + 1 Else intCnt = 1 sCurrentField = sFieldName End If GetCount = intCnt End Function
then use the is query
select [Customer Number], [Invoice Date], GetCount([Customer Number]) AS RowCount from orders order by [Customer Number], [Invoice Date]
|
|
|
|