Audit Trail with User's Name

P

PC User

<<BACKGROUND>>

I've made Audit Trail fields to track the actual changes to the data.
As a routine, I add 4 fields to my main data tables:

CreatedBy, CreatedWhen, EditedBy, EditedWhen

On my forms, I add controls for all four and set the Visible property
of them to False. The CreatedWhen control is set to default to Now().
The CreatedBy control defaults to fOSUsername() (which is a function
found at http://www.mvps.org/access/api/api0008.htm to get the network
logon ID of the user). In the Before Update event of the form, I add
the following code:

Me!EditedBy = fOSUserName()
Me!EditedWhen = Now()

This results in a date and time stamp of when the record was created
and Edited and Eho created and/or edited it.

<<PROBLEM>>

In our company's Outlook Contact list the fields include the userID,
the first name and the last name. I've linked a table to this Outlook
Contact List and made a query with one of the fields to concatenate
the first and last names.

FullName: [Global Address List]![First] & " " & [Global Address
List]![Last]

In the second column of the query I have the userID which has the
field name [Account]. My question is that in the Audit Trail fields
mentioned above, I want to programically have the user's full name be
inserted into the fields CreatedBy and EditedBy instead of the userID
number from the network. How do I link the [FullName] from the query
to these fields so that the user's full name is placed into the main
table.

Thanks,
PC
 
P

PC User

I did find a solution and for those of you who have a similar problem
I'm posting the answer.

Code:
===============================================================
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo PROC_ERR

Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
frmCurrentForm![LastModified] = NOW

Dim strUser As String
Dim strFirstName As String
Dim strLastName As Stringng

Me!EditedWhen = NOW()
strUser = fOSUserName()
strFirstName = DLookup("[First]", "Global Address List", "[Account]
='" & strUser & "'")
strLastName = DLookup("[Last]", "Global Address List", "[Account] ='"
& strUser & "'")
Me!EditedBy = strFirstName & " " & strLastName

Exit Sub

PROC_ERR:
MsgBox "The following error occured: " & Error$
Resume Next
End Sub
===============================================================
 

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

Similar Threads

audit trail 7
Audit Trail 6
Audit Trail 1
Report from Audit Trail 5
Audit Trail 5
Audit Trail 2
Audit Trail for Access 3
Allen Browne's Audit Trail Not Working 1

Top