Applecore Pages on Microsoft Access

Saving the Date a Record was Last Edited

If you are using a form to enter data, as you should be, then automatically adding data, such as the date that the record was last edited, or who last edited the record, becomes quite easy by use of the form's BeforeUpdate event. First add a Date/Time field called AmendDate to the table. Then open the form in Design Mode, and add the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me!AmendDate=Now
End Sub

This will add the time and date that the record was amended to the table. Anther option is to include just adding the date, in which case you would use 'Date' instead of 'Now'. If you want to also show who amended the record last, then you need a way of getting the name of the user. If you have implemented Access security, then you can use the CurrentUser function to return the current user account. If you haven't done this, and your database is on a Windows NT system, then you should be able to use an API, such as GetUserNameA, as shown on The Access Web.

If you are interested in the date that the record was added to the table, then you replace the Before Update event with the Before Insert event:

Private Sub Form_BeforeInsert(Cancel As Integer)
    Me!AddDate=Now
End Sub

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 15:01:39