Display the system user in a record

P

Peter

Hi all again..and once again thanks for a great place...i have a humble
question..
I figured out how to display the date and time for the modification of a
record...but how do i display the system user and is it possible to also
display when a record was created?
 
D

Douglas J. Steele

For record creation date/time, add a CreatedDtm field to the table and set
its default to Now. Nothing else should be required.

To grab the user id, see the code in
http://www.mvps.org/access/api/api0008.htm at "The Access Web".
Unfortunately, you can't set the Default for a field in a table to a user
defined function, so you have to add code in your form's BeforeUpdate event.
 
P

Peter

Hi again, found the code..and how do i populate my fOSUserName
textfield...something like:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

' Set bound controls to system date and time.
DateModified = Date
TimeModified = Time()

BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub?
 
D

Douglas J. Steele

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

' Set bound controls to system date and time and current user name
Me.DateModified = Now()
Me.ModifiedBy = fOSUserName()

BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub

Of course, that presupposes that you've copied the code from
http://www.mvps.org/access/api/api0008.htm at "The Access Web" into a module
in your application.

Note, too, that I eliminated your TimeModified field, and used the Now()
function to put both the date and time into the DateModified field. The Date
data type is intended for timestamps: when you use only Date, what's stored
is actually 00:00:00 on that day (and if you use only Time, it's that time
on 30 Dec, 1899). Should you need only the date or only the time, use the
DateValue or TimeValue functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top