Take a look at RowNumbering.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.
This little demo file includes illustrations of queries for numbering or ranking rows, including by group. The most efficient method is by a JOIN of two instances of the table, for which the query in my demo is:
SELECT COUNT(*) AS RowNumber, T1.CustomerID,
T1.TransactionDate, T1.TransactionAmount
FROM Transactions AS T1 INNER JOIN Transactions AS T2
ON (T2.TransactionID<=T1.TransactionID
OR T2.TransactionDate<>T1.TransactionDate)
AND (T2.TransactionDate<=T1.TransactionDate)
AND (T2.CustomerID=T1.CustomerID)
GROUP BY T1.CustomerID, T1.TransactionDate,
T1.TransactionAmount, T1.TransactionID;
For an updatable query the same can be done by calling the VBA DCount function:
SELECT DCOUNT("*","Transactions","CustomerID = " & CustomerID &
" AND TransactionDate <= #" & FORMAT(TransactionDate,"yyyy-mm-dd") &
"# AND (TransactionID <= " & TransactionID &
" OR TransactionDate <> #" & FORMAT(TransactionDate,"yyyy-mm-dd") & "#)") AS RowNumber, CustomerID, TransactionDate, TransactionAmount
FROM Transactions
ORDER BY CustomerID, TransactionDate, TransactionID;
These queries start a new sequence per CustomerID and numbers the rows in transaction date order. Note how the primary key TransactionID column is brought into play in each case as the tie-breaker in the event of two or more transactions occurring on the same
date.
For future reference, please do not piggy back a new question on an old thread. Start a new thread, and include a hyperlink to the earlier thread if you wish to refer to it.