A family of Microsoft relational database management systems designed for ease of use.
You might like to take a look at RowNumbering.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to amend the form design accordingly.
If you have difficulty opening the link, copy the link (NB, not the link location) and paste it into your browser's address bar.
One of the queries in this little demo returns an updatable recordset with sequential row numbers per customer. It does this by calling the VBA DCount function, rather than using the more efficient, but non-updatable methods illustrated in two other queries using a join or a subquery. The query is as follows:
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;
If a TransactionNumber column is added to the Transactions table the query can be converted as below to an UPDATE statement which inserts the computed transaction numbers per customer into the TransactionNumber column:
UPDATE Transactions
SET TransactionNumber =
DCOUNT("*","Transactions","CustomerID = " & CustomerID & "
AND TransactionDate <= #" & Format(TransactionDate,"yyyy-mm-dd") & "#
AND (TransactionID <= " & TransactionID & "
OR TransactionDate <> #" & Format(TransactionDate,"yyyy-mm-dd") & "#)");
As Tom pointed out earlier, it is necessary to identify a sort order per customer to do this. In the above examples the sort order is by TransactionDate, and, because there could be two or more transactions per customer on the same date, the primary key TransactionID column is brought into play as the tie breaker.