You can capture and track the name of the user and the current Date & Time every time a record is added or changed in a table. Here's how:
1. Go into design view of the table.
2. Create 4 new fields: CreatedDate, CreatedByUser, ChangedDate, ChangedByUser.
2. Set the 2 User fields to data type Text, with a field size the length of a login ID.
3. Set the 2 Date/Time fields to data type Date/Time.
4. For date only, set format to Short Date. For Date & Time set format to General.
5. Set the default value of CreatedDate to Date() for date only; Now() for date & time.
6. Go into design view of your data entry form.
7. Capture the Access loginID with CurrentUser() or NT's login with Environ("username").
8. Use the Before Insert event to load the user logidID when adding a new record.
9. Use the Before Update event to load the user & datestamp when updating a record.
Here's an example of how to load a value:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me!UpdatedByUser = Environ("username") ' this is the NT loginID
Me!UpdatedByUser = CurrentUser() ' use this line if you want the Access loginID
Me!UpdatedDate = Date()
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.