Log changes using Insert Into

BobJones

Registered User.
Local time
Today, 04:15
Joined
Jun 13, 2006
Messages
42
Basically my boss wants it so that all changes made by staff to the database are logged. Logging the username, datachanged, form the data was changed on, and the date and time...
I made a public sub but it doesnt seem to be working, any ideas? I was thinking about putting it on the afterupdate of the controls, unless anyone has an easier, more efficient way of doing this?

Public Sub logData(ByVal uName As String, ByVal data As String, ByVal fName As String)
Dim strSQL As String
Dim day, time As String
day = Format(Date, "dd/mm/YYYY")
time = Format(Now, "hh:mm:ss")

strSQL = "INSERT INTO 'Log' ('Username', 'DataChanged', 'Date', 'Time', 'FormChangedOn')" & _
"VALUES ('" & uName & "', '" & data & "''" & day & "','" & time & "', '" & fName & "');"

DoCmd.RunSQL (strSQL)
End Sub
 
Search for "Audit Trail" there are excellent examples posted


Col
 
SQL should probably be

strSQL = "INSERT INTO Log (Username, DataChanged, [Date], [Time], FormChangedOn)" & _
"VALUES ('" & uName & "', '" & data & "', '" & day & "','" & time & "', '" & fName & "');"

as you only need to quote data, and you had a missing comma :)
 

Users who are viewing this thread

Back
Top Bottom