View Full Version : Help Creating a SIMPLE Audit Trail


jaytee716
06-03-2008, 09:02 AM
Ok, so I've been working on this for a couple weeks searching articles and attempting different modules and coding but have been stumped once again.

I have one main table called tTestScripts and added 2 columns, "Username" and "DateTime". When the user enters information in the form, on close I want to put their XP Username and date and time in the appropriate columns. I do not want to have a log in when the user enters Access. The farthest that I came to accomplishing this was making a text box in the form and for the control put in =osusername (or something like that, not sure) and it populated the field but I couldn't figure out how to get it to write back to the table. So I did more searching and found an advanced module (which I tried and tweaked but couldn't get to work). Then I found this:
Private Sub Form_BeforeUpdate(Cancel As Integer)
' Log the user details to the table

Me!SystemUsername = User_FX
Me!RecordChanged = Now()
End sub
Which does not work either....and yes I changed this to fit my column names in my form, but maybe I didn't tell this code to put the information into my table.

All that I am trying to do is to update the table with the XP Username along with the date and time when the form is closed or loaded, or at this point anytime the user is in the form.

Can anybody help me and point me into the right direction?

You all have been a great help so far and appreciate everything everyone does here!

RuralGuy
06-03-2008, 04:27 PM
If the two names are *just* fields in your bound table and not Controls on the form then use:
[SystemUsername] = User_FX
[RecordChanged] = Now()

DCrake
06-03-2008, 11:59 PM
I am ever the pessamist when it comes to writing audit trails and validation routines, working one the theory "if someone wants to crash it it will" or GIGO.

It's Ok using the Windows login name, however can you be sure that the person who logged into the computer is the person who actual opened the database and made the changes. I would also capture the computer name as well.

My audit trails usually capture:-

Computer Name
Windows Login Name
Application Login Name
Application User Password
Date/Time Stamp
Action Taken

This then gives you full traceability without compromising the users integrity. Situations have arisen in the past where a user has left their computer on and someone else has opended the application made a change and exited the application. Also you may consider putting a time out routine in your app so that if the app is left idle for a set number of miuntes the app closes. This prevent sthe user from walking away from the PC and leave the app open. Again someone else may take advantage of this to make changes during the authorised users absence.

CodeMaster::cool:

Lightwave
06-04-2008, 06:20 AM
Not sure that you need this but... an example audit trail database from the forum.

http://www.access-programmers.co.uk/forums/showthread.php?t=140387