calculating data for a field based on another field

briandavis

Registered User.
Local time
Today, 12:45
Joined
May 18, 2004
Messages
15
In an employee database two fields I have are, hiredate and seniority. Is it possible to have access automatically enter a value in the seniority field based on the hire date. For example the person with the oldest hire date will be given a seniority of 1. the second oldest hire date gets 2 and so on.. For another example: say the employee who's seniority is 237 retires. If I delete his record from the table it will automatically recalculate and thus the employee who was 238 moves up to 237 and in fact all below this move up in the standings.

Thanks
 
Oh, and we don't really do calculations in tables, so I moved this thread to queries.
 
Have a query sorting your table by StartDate (ascending)
Call it qrySeniority

Then, put this in a module:

Code:
Public Sub ReviseSeniority()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim lngCounter As Long


    Set db = CurrentDb
    Set rs = db.OpenRecordset("qrySeniority")

    With rs
        .MoveFirst
        Do While Not .EOF
            lngCounter = lngCounter + 1
            .Edit
            .Fields("Seniority") = lngCounter
            .Update
            .MoveNext
         Loop
         .Close
     End With
     db.Close

    Set rs = Nothing  
    Set db = Nothing

Exit Sub


Call that sub whenever you want to update the table.
 
issue solved

Sorry, I went away on vacation since I posted this question.

Wanted you to know it works great!

I hope yo don't get tired of hearing that you're a genius!
 
Oh, not at all!

I love to hear it!!

. . .


oh...I see.
you're talking about Mile...
hmph.



ROFL!
 

Users who are viewing this thread

Back
Top Bottom