update Rank Order field (1 Viewer)

markqu@msn.com

New member
Local time
Today, 00:37
Joined
Nov 18, 2008
Messages
2
I have a tbl_Students with Name, Score and Rank as fields. Name and Score are entered via an access form. After all scores are entered, I want to push a button and update the Rank field in the same table according to the student's score. Student with the highest score is Rank 1, lowest score Ranks last (recordcount) or thereabouts. Where two or more students have the same score, the Rank must still increment.

Student Score Rank
Student1 91 1
Student2 88 2
Student3 79 3
Student4 79 4
Student5 79 5
Student6 77 6

Can this be done eloquenlty with an Access expression in a query? How?

I thought of walking through a record set which is sorted in decending order and updating each record to some VBA record counter. Seems a bit klugy but im open to ideas or code examples.
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:37
Joined
Aug 30, 2003
Messages
36,125
Personally I wouldn't store the rank, I'd just calculate in a query. That saves you having to redo it when records are edited, which they inevitably are. Typical methods use either a DCount or subquery to figure the rank. If you insist on storing it, I assume an update query could use the same method.
 

markqu@msn.com

New member
Local time
Today, 00:37
Joined
Nov 18, 2008
Messages
2
The Ranking must be stored in the table. It is a representative snapshot for one event.

DCount returns the number of records in a record set. How can you use it to update the Rank field of a specific record as my exmple query result set looks like?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:37
Joined
Aug 30, 2003
Messages
36,125
With a criteria that counted how many have scores equal to or greater than the current record. You'd want to add another field to break ties, presumably your student field.
 

Users who are viewing this thread

Top Bottom