Audit Trail using VBA

matthewnsarah07

Registered User.
Local time
Today, 02:22
Joined
Feb 19, 2008
Messages
192
I want to add an audit trail to my existing database.
Basically when certain button are clicked I want the On Click event to add an entry into tblAudit.

tblAudit contains [Request Number], [Action], [Date] [Time] [User]

I want the request number to be taken from the form field of the same name, Action will be a set phrase such as "Record Updated" and Date, Time and User just stamped e.g. Date() etc.

How would I go about writing the code to insert this record, can it be done though a query more easily?

Thanks for your help
 
There have been several threads about audit trails recently. Try searching the forum for more information
 
I've looked through a few but I am looking for a way to do it exactly how I've described to make it of use

Any help please?
 
This should work for you... It uses DAO recordsets which is a bit dated but most people find it easier to start with than ADO (which most people will probably recommend once you get the hang of it!)

Code:
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

set dbs = application.currentDB
set rst = dbs.OpenRecordset("tblAudit")

With rst
.Addnew
![Request Number ] = whatever
![Action] = whatever
![Time] = Now()     ' it's better to store date and time together!
![User] = Application.CurrentUser      ' if you're using Access security
.Update
End With

set dbs = nothing
set rst = nothing

Hope this helps,

Tom
 

Users who are viewing this thread

Back
Top Bottom