Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Database record changes - How to audit?

Posted on 2015-01-28
5
Medium Priority
?
126 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 58
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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 85
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

926 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