Dear Krisse:
As a starting point, you can try this:
SELECT ContractNo, AcctYear, AccountNo,
(SELECT COUNT(*) + 1 FROM tblDetail T1
WHERE T1.ContractNo = T.ContractNo
AND T1.AccountNo < T.AccountNo) AS Rank
FROM tblDetail T
ORDER BY ContractNo, AccountNo
Please let me know if this helps, and if I can be of any other
assistance.
Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts