here is some code that will scan thru a query, and set the 'ranking' field.
You provide the query, sorted as needed, the group and the field to write the rank# to.
If you use various Groups to rank, it resets on that group. So the query must sort by: group, Value (descending)
give: query, groupField, RankField
usage:
RankByGrp "qsTopSales","EmpID","RANK"
Code:
'rank items in query, break on GROUPBY
Public Sub RankByGrp(pvQry, ByVal pvGroupBy, ByVal pvRankFld)
'pvQry : query name, sorted by GroupBy then value# to rank
'pvGroupBy : field to group the rankings on. Rank resets to 1, when the Group changes
'pvRankFld : fieldname to write the rank#
Dim rst 'As Recordset
Dim lNum As Long
Dim vPrevGrp, vGrp
lNum = 1
Set rst = CurrentDb.OpenRecordset(pvQry)
With rst
While Not .EOF
vGrp = .Fields(pvRankFld).Value & ""
If vGrp <> vPrevGrp Then lNum = 1
.Fields(pvRankFld) = lNum
.Update
lNum = lNum + 1
.MoveNext
vPrevGrp = vGrp
Wend
End With
Set rst = Nothing
End Sub