Solved

Database record changes - How to audit?

Posted on 2015-01-28
5
116 Views
Last Modified: 2015-02-02
I have a table named tblAudit.  In this table in addition to an auto-number ID field are 7 fields.  They are:

EditDate, User, RecordID, SourceTable, SourceField, BeforeValue, and AfterValue.

Any time a change is made be it edit, addition, or deletion is made I need the audit table to have a record made to it capturing the values.  How can I do this?  Do I need some code for every form?  Or a module that works for every change?

What would to code look like?  I've never done this before.

--Steve
0
Comment
Question by:SteveL13
  • 2
  • 2
5 Comments
 
LVL 57
ID: 40575184
You would add in some code and hook it up in every form.  See:

http://allenbrowne.com/appaudit.html

Bounce back if you have any questions (I'm sure you will).

Jim.
0
 

Author Comment

by:SteveL13
ID: 40575822
Wow!  Lots to absorb.  Back to you after I review and see what I can do with it all.  Thanks so far.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40577043
If you're using 2010 or later you can use the new Data macros. Scott Gem shows how to do this here: https://scottgem.wordpress.com/2012/10/18/audit-trail-using-data-macros-2/
0
 

Author Comment

by:SteveL13
ID: 40577544
Scott,

I like your suggestion.  Just a couple of comments:

When adding a new record I get a record in the tblAuditTrail.  But I wish it would capture the value I entered in each field for FieldName and NewValue.  It isn't doing that.

When deleting a record I wish it would capture the record ID that was deleted.  It isn't doing that.

Can the code be altered to do these things?
0
 
LVL 84
ID: 40584980
Can the code be altered to do these things?
You haven't posted any code or screenshots, so the only way I can answer that is "Maybe" ...
But I wish it would capture the value I entered in each field for FieldName and NewValue.  It isn't doing that.
It's up to you to capture those values if you want. You'd need to use the "SetValue" action for each field that you want to capture.
When deleting a record I wish it would capture the record ID that was deleted.  It isn't doing that.
Data Macros offer a BeforeDelete and AFterDelete action, so you could probably write to the audit log in the BeforeDelete event.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question