Add data to table field when record is modified

I have two field in a table...  LastModUser (short text field) and LastModDate (short date field).  When the record is either added or modified I want the LastModUser  field to be populated with the user's login and I want the LastModDate field to be populated with the current date (short date).

How can I do this?  I assume it will be in the beforeupdate event of the record?  Or?

--Steve
SteveL13Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
PatHartmanConnect With a Mentor Commented:
The code goes into the BeforeUpdate event of the Form.
In my apps, the code is always:
    Me.ChangeBy = Forms!frmLogin!txtEmpID
    Me.ChangeDT = Now()

Open in new window

Because I keep the login form open (but hidden).  Where you get the LoginID depends on how the user logs in and what you do with the information he provides.

PS - the datetime data type is a double precision number with the integer being the number of days since 12/30/1899 and time being the time of day.  Formatting is a visual thing and is done when the date is displayed on a form or report.  I use Now() because I prefer to include time of day in my "timestamps" but the Date() function will just return the current date so you can use that if you prefer.  TOD is especially important in my current app because we have to extract updates and send them off to the State of Connecticut.  Our extract runs at 8 PM and selects anything that was updated after the last extract.  So if something is updated at 8:05 it doesn't get sent until the following day.
0
 
SteveL13Author Commented:
Pat,

I should have been more specific regarding the LastModUser field.  I meant the computer logic name.  There is no database login form.  How would I do that?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
You can grab the computer's login name with this:

Environ("UserName")

Or use the API:

https://support.microsoft.com/kb/161394/en-us
0
 
SteveL13Author Commented:
Both very helpful.  Thank you.
0
All Courses

From novice to tech pro — start learning today.