Solved

Transaction Log in Access Database

Posted on 2016-08-16
14
41 Views
Last Modified: 2016-09-06
We are looking for a way to create a transaction log in Access 2010, when changes are made in a table, this transaction log populates when the change was made. We want a record created in a transaction log to keep track of any changes in a table. Specifically, we have a table with multiple columns that have check boxes (Columns 1-5 on the attached image). We are looking for a way to track when those check boxes are checked. On our table that has multiple columns with check boxes (Table 1), there is an ID column. On the transaction log, we need it to reference the ID column from the table (Table 1) and which column was checked (Columns 1-5). I hope that makes sense. Thanks!!
Example.jpg
0
Comment
Question by:brasiman
  • 4
  • 4
  • 2
  • +3
14 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 41758624
Are you changing the data directly in the table or are you doing the changes via a form?  Access doesn't have table triggers like SQL server.

OM Gang
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 41758627
If you are updating using bound forms, you can use the forms before update event to trap the New value and Old value and write them to a log. You'd need to write a piece of code that cycles all the appropriate controls and compares the oldvalue and value values and write where they're different along with any other data you want.


Kelvin
0
 

Author Comment

by:brasiman
ID: 41758628
We will be changing the data in a form, which is tied to the table.
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 41758630
If you are updating directly into the table, or use unbound forms, then sadly, you're out of luck


Kelvin
0
 

Author Comment

by:brasiman
ID: 41758631
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 41758632
Forms tied to the table are bound forms.

K
0
 

Author Comment

by:brasiman
ID: 41758633
I can change it so we are entering the data on the table.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 3

Expert Comment

by:bfuchs
ID: 41758636
I have the following function that does that, just call it from the forms BeforeUpdate event.
Public Function SaveHistoryChanges(Optional sTable As String = "", Optional sField As String = "", Optional vValue As Variant = "", Optional lID As Long = 0)
    Dim ssql As String, cNtrl As Control
    If Len(sTable) = 0 Then sTable = Screen.ActiveForm.Name
    If lID = 0 Then lID = Nz(Screen.ActiveForm.ID, 0)
    
    On Error Resume Next
    For Each cNtrl In Screen.ActiveForm.Controls
        If (TypeOf cNtrl Is TextBox Or TypeOf cNtrl Is ComboBox Or TypeOf cNtrl Is CheckBox Or cNtrl.ControlType = 107) Then
            If Nz(cNtrl.Value) <> Nz(cNtrl.OldValue) And cNtrl.Visible = True And cNtrl.Enabled = True Then
                If Not IsNull(cNtrl.OldValue) And Not (TypeOf cNtrl Is CheckBox) Then
                    If Nz(tLookup("ID", "HistoryChanges", "TableName = '" & sTable & "' and FieldName = '" & cNtrl.ControlSource & "' and TableID = " & lID), 0) = 0 Then
                        ssql = "Insert into HistoryChanges (TableName, FieldName, Value, TableID)"
                        ssql = ssql & " Values ('" & sTable & "','" & cNtrl.ControlSource & "','" & cNtrl.OldValue & "'," & lID & ")"
                        CurrentProject.Connection.Execute ssql
                    End If
                End If
                ssql = "Insert into HistoryChanges (TableName, FieldName, Value, Initial, TableID)"
                ssql = ssql & " Values ('" & sTable & "','" & cNtrl.ControlSource & "','" & cNtrl.Value & "','" & GetInitial & "'," & lID & ")"
                CurrentProject.Connection.Execute ssql
                
            End If
        End If
    Next

End Function

Open in new window

0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 41758639
"I can change it so we are entering the data on the table. "

No!, you must use bound forms!

K

The code above is just what is needed.
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points (awarded by participants)
ID: 41758656
Access 2010 does have data macros attached to tables, which are like triggers in SQL and other db's.   Only requires that you use the new ace format.

You can also do it through bound forms as has been suggested.  Here is a complete solution:

http://allenbrowne.com/appaudit.html

Jim
0
 
LVL 75
ID: 41758703
Yes as Jim notes, you can use Data Macros if you are using the ACCDB format. I've tested this and created a transaction log and it seems to work quite well.  Just an FYI.
0
 

Author Comment

by:brasiman
ID: 41761634
Hi bfuchs, do I need to change any of the code text to match my columns and table name? On my first question, I attached an image of my table and column names. Thanks!
0
 
LVL 3

Expert Comment

by:bfuchs
ID: 41761655
No, the only thing needed is to create a table named HistoryChanges with the following fields.
 TableName, FieldName, Value, Initial, TableID
0
 
LVL 75
ID: 41785789
Abandon Q
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now