Solved

Database record changes - How to audit?

Posted on 2015-01-28
5
117 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

679 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