DonLo sent me this message, below. Why would his Before Insert event would be missing? If there's anything wrong with or missing from the FAQ, I'd like to correct it.
Hi Elizabeth,
Your "Date Stamp..." (see below) faq is excellent! Thanks for posting it - it is exactly what I want to do. I followed you up to Step 6, but I'm a little unclear on the Before Insert and the Before Update events. I see a Before Update property for each of the fields, but not a Before Insert. So where does the code go?
Thanks for your help
*********************
Date stamp records and capture User name when data is added or changed
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
Hi Elizabeth,
Your "Date Stamp..." (see below) faq is excellent! Thanks for posting it - it is exactly what I want to do. I followed you up to Step 6, but I'm a little unclear on the Before Insert and the Before Update events. I see a Before Update property for each of the fields, but not a Before Insert. So where does the code go?
Thanks for your help
*********************
Date stamp records and capture User name when data is added or changed
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