Audit Trail (1 Viewer)

ranjeewaf9

Registered User.
Local time
Today, 07:35
Joined
Aug 23, 2010
Messages
18
Hi Bob,

Don't worry I realised what I did wrong there. It's working now. Thanks. However I would like some guidance on how to use the code on a form where multiple controls have to be checked for duplicates (e.g. like in the frm_EdData).
 

boblarson

Smeghead
Local time
Yesterday, 23:35
Joined
Jan 12, 2001
Messages
32,059
Hi Bob,

Don't worry I realised what I did wrong there. It's working now. Thanks. However I would like some guidance on how to use the code on a form where multiple controls have to be checked for duplicates (e.g. like in the frm_EdData).
Can you give me an example of how a record would contain duplicates? Which fields are we talking about (their actual field names and datatypes) and the control names for which they are bound?
 

ranjeewaf9

Registered User.
Local time
Today, 07:35
Joined
Aug 23, 2010
Messages
18
Hi Bob,

In the frm_EdData there are multiple controls where I don't want duplicates. The form is linked to the tbl_IpAdd. In the form there are 3 fields that need to be checked for duplicates when entering data and they are "Employee Details", "Machine Details" and IP Address. Once a machine is allocated to an employee with a specific IP address that IP Address cannot be used again by another employee in the same network. Also the same machine cannot be used by two employees at the same time. That's the reason why I don't need these fields to be duplicated.

The person who assigns the machine may simply assign without the knowledge that this machine was previously assigned to someone. Suppose if an employee leave the machine will still be under his name unless the record is changed. So if this machine is assigned to a new employee it should prompt that the machine trying to assign would create duplicate values as it's already been allocated to the employee who has already left. This will make the inputter realise that this machine is under someone else's name already and therefore should amend the old record first before adding the new one. These duplicates will ruin the very purpose of the database. Down the line if I see the same machine is allocated to several employees who have changed departments it would be impossible for me to find out who's using which machine at any given time unless I physically go and find out to each and every one of them till I find the particular machine I'm looking for.

That's the reason I made this database and I need to have an audit trail just to find out who changed what and when. This will make the inputters accountable for their actions and can find out if any record has been added or amended in error.

The field names are "Machine Details", "Employee Details" and "IP Address". Data type of all the fields is Text and their control names are the same as field names. I have used combo boxes for them in the form.

Hope this gives you an idea what this database is all about. Pls. feel free to ask me if you require more info. Thanks.
 

ranjeewaf9

Registered User.
Local time
Today, 07:35
Joined
Aug 23, 2010
Messages
18
Hi Bob,

Is it possible to do the Dcount for combo boxes? If so how can I do it? I figured out it works fine with text boxes. But in the frm_EdData I have used combo boxes which makes editing records easy. It's for these that I struggle to use Dcount to check for duplicates in the beforeupdate event. Your help is much appreciated.
 

ddt1972

New member
Local time
Today, 15:35
Joined
Jan 20, 2011
Messages
6
All,

I have implemented the audit trail, and it works great, except for one of my forms which uses checkboxes. The audit trail does not record changes to yes/no boxes. Is there a way to make it recognize and record changes to these?
 

boblarson

Smeghead
Local time
Yesterday, 23:35
Joined
Jan 12, 2001
Messages
32,059
All,

I have implemented the audit trail, and it works great, except for one of my forms which uses checkboxes. The audit trail does not record changes to yes/no boxes. Is there a way to make it recognize and record changes to these?

Which one are you using?
 

Jim229

Registered User.
Local time
Today, 01:35
Joined
Feb 1, 2011
Messages
11
I want to thank all that have posted code and methods for doing this, Great Job All of you. I unfortunately must ask if you can help me one a little more.

I created a database for tracking Police Records several years back and now have a new problem with someone making changes to those records and deleting them
which causes a major problem for police Departments.

Due to the large number of fields on my forms and the need to track all changes to any field, I don't need to track the field if it is Null unless that value is changed later, and I don't need to track record creation because I already have a field that must be filled before a record can be created. Because of all of this I have come to the conclusion I need to use a separate table to track these changes instead of just one field. What i can't seem to get past is how to do that without actually creating an Audit Table that has every field I use in all 4 of the tables I have in the database and if I do go that route how I would be able to manage adding future tables or fields to that table once data was present.

This is a very small department, they never reach the limit of entries before replication error in an Access database so I use straight Access and store the database on a Network drive instead of locally. Only 1 computer accesses the database since the Front End is only loaded on that computer.

I have 5 users and 1 or 2 of them is making changes that I need to put a stop to. We have a suspect but haven't been able to catch the person so I looked at the problem and wanted to go to an Audit Trail which is what I always wanted but had never seen a way to do it until I found this thread. I have a soft Spot for this department because they are very small and really have no budget to deal with this type of thing or to get a full blown Computer Assisted Dispatch system, most of the good ones are really high dollar.

Please help. If I were being paid for this I wouldn't even ask but in this case with no money involved I'm way more concerned with providing a working solution than being prideful and beating my head against a rock. I have a programming back ground but can't seem to get a handle on VB.

I do have the Second Version of Ghudson's AuditTrail working at the moment but that blank line it throws is making it hard for me to picture a way to drop that so the memo field can be read into a Text string then parsed out using a query. I did notice the memo field is space delimited so it can be parsed I just can't figure out the VB code to do it.
 

scubadiver007

Registered User.
Local time
Yesterday, 23:35
Joined
Nov 30, 2010
Messages
317
The audittrail mdb is brilliant but is there anyway I can adapt it so that I am able to insert the audit statements into separate records in another child table.

thanks
 

Jim229

Registered User.
Local time
Today, 01:35
Joined
Feb 1, 2011
Messages
11
ScubaDiver, It is possible to do what you want. I use that as a back up of sorts. While it does make the information redundant because in my implementation I keep the Audit data in a separate table as well as each table that has an entry changed. I plan to remove this from the tables though.

If you keep the Audit data in a separate table it is cleaner in the overall database development and you can use queries to sort the data if you only want to see what changes were made to specific tables of data. The key is keeping track of data fields used to make the audit trail possible.

Essentially when you reference the area to store the changes you will have to ref the complete table name instead of just using 'Me!' and you will have to modify the Audit function to accept the different tables instead of looking for just the main table that it currently uses to store data.

Hope this helps.
 

Jim229

Registered User.
Local time
Today, 01:35
Joined
Feb 1, 2011
Messages
11
ScubaDiver,

I attached a zip file of a database I've been working on that uses ghudsons version of Audit trail that saves the changes in a separate table. There are 2 photos included in the zip file. for some reason my Winzip wouldn't take the whole photo folder into the archive. You will need to create a folder called "Photos" and put the murphy.bmp file in it for the mdb to work correctly.

Administrator is the user name and Administrator is the password in this version.

Hope you can use this as an example to see how the code goes together so yo can modify the code to work with your database.

Code:
Call Audit_Trail(Me, "VID", VID.Value)

I modified the control fields to match the call for the Audit function. The field referenced in the call is the key field for the table you are tracking changes in. The code referenced above is from the CTW entry form so yo can compare how it relates to the different tables. This call is changed for each table that tracks changes and can be queried to specify what data is output in a report.
 

Attachments

  • CAD.zip
    1 MB · Views: 271

scubadiver007

Registered User.
Local time
Yesterday, 23:35
Joined
Nov 30, 2010
Messages
317
Jim229,

Thanks for the database. I am not an expert and this is a bit complicated for me.

I only need to track changes for one table.
 

Jim229

Registered User.
Local time
Today, 01:35
Joined
Feb 1, 2011
Messages
11
It's actually not that hard. Look at the Utility functions module, highlight and copy the section that is the audit trail code. You will be able to see where it switches to a calendar function. Go to your database and add a new module and then paste the copied code in it and save it as Module 1 or if you already have a Module1 use the next number that is available. Then located the form code modules above the Modules section and find a form that uses the audit trail. In most forms I put that function call in the top of the form code. Add that to your own forms where you need it. make sure you copy the tblaudit table to yours or create it yourself. save everything, I recommend you close and restart the database but that isn't required in most cases, and reopen it and it should work fine from there.

Keep in mind that code is setup to read the user login who is logged into Access. There is a commented line of code in the Audit trail code that you copied to Module1 that you can use that will read the login from the Windows login.
 

chelbosul

Registred User Level Easy
Local time
Today, 08:35
Joined
Jun 9, 2010
Messages
8
I had that problem earlier. I found out that when a form with subform is displayed and edits are being done to the subform the active form is the parent form and not the subform.

This seems to be the effect that this line in the Audit Trail had:

Set frm = Screen.ActiveForm

My solution:

1. Pass the form as an argument of the function

Function AuditTrail(frm as Form)

2. Comment out these lines in the code

'Dim frm as Form
'Set frm = Screen.ActiveForm

3. Call the function in the BeforeUpdate event of the form and or subform as
follows:

Call AuditTrail(Me)


HTH,

Lyn

Hy nice with this audit trail , but i still did not manage to solve this problem when shoud record changes from a subform ...
I try this code from your post but still nothing ....

I have one main form with 1 subform and 4 subforms in 1 subform ......
Even so ... changes are only in subform ....still i get the error that can not be found tblauditrail

Please help with an exact sample of beforeupdate....

thanks in advance
 

boblarson

Smeghead
Local time
Yesterday, 23:35
Joined
Jan 12, 2001
Messages
32,059
Hy nice with this audit trail , but i still did not manage to solve this problem when shoud record changes from a subform ...
I try this code from your post but still nothing ....

I have one main form with 1 subform and 4 subforms in 1 subform ......
Even so ... changes are only in subform ....still i get the error that can not be found tblauditrail

Please help with an exact sample of beforeupdate....

thanks in advance
chelbosul:

What code did you try in the before update event?
 

latestgood

Registered User.
Local time
Yesterday, 23:35
Joined
May 19, 2011
Messages
15
After School Program Needs your help (sdd audit trail)

Hello,

I have simple after school program. I like to add audit trail to expense form. Although, I've been trying to apply the code, I've been unsuccessful. Anyone who's has coding knowledge should be be able to apply it easily using the code given... I've attached my file and it'll be great if someone can add the code for me and maybe I can learn to for the future reference.

Thank you,
 

Attachments

  • After School Activity.mdb
    352 KB · Views: 240

boblarson

Smeghead
Local time
Yesterday, 23:35
Joined
Jan 12, 2001
Messages
32,059
Re: After School Program Needs your help (sdd audit trail)

Hello,

I have simple after school program. I like to add audit trail to expense form. Although, I've been trying to apply the code, I've been unsuccessful. Anyone who's has coding knowledge should be be able to apply it easily using the code given... I've attached my file and it'll be great if someone can add the code for me and maybe I can learn to for the future reference.

Thank you,
Here's your database back with an audit trail implemented. Look at the code behind the form's Before Update event and Delete event. You would just have to do similar on any other forms.
 

Attachments

  • After School Activity.mdb
    312 KB · Views: 305

latestgood

Registered User.
Local time
Yesterday, 23:35
Joined
May 19, 2011
Messages
15
After School Program needs help with Audit trail code??

Hello,

I am currently building after school program to better track expenses. I wanted to add audit trail to expense budget form and Expense Items form. Someone who has vba code knowledge should be able to easily apply the code. But due to my limited knowledge, I can't understand the code that's posted. It'll be great if someone can help us out. I've attached my database and links to vba code for audit trail.

Again, thank you for your help.
 

Attachments

  • After School Program.mdb
    704 KB · Views: 193

SpirituaLee

Registered User.
Local time
Today, 07:35
Joined
Dec 5, 2007
Messages
16
Oh dear, dare I re-awaken the much disturbed beast?!

If anyone's willing to assist, I've implemented the 'table' version of the audit trail, and works for my main form, but not my subform (which is based on a real frankenstein of tables and queries), although despite the error, it does log the changes in the audit trail table.

I've read the entire thread, but as my VBA abilities range between zero and fleeting, I can't remove the 3251 error (Operation is not supported for this type of object).

The erroring (on subform only) code I'm using is below..

Code:
Option Compare Database
Option Explicit
Dim dbs As DAO.Database
Dim sAuditTable As String
Dim sSQL As String
Dim sTable As String        'Table where the record is being edited
Dim CTL As Control          'The control in the form being edited
Dim sFrom As String         'Original Data in the control
Dim sTo As String           'What the original data was changed to
Dim sPCName As String       'Name of the PC that is being used
Dim sPCUser As String       'Name of the User on the Networked PC
Dim sDBUser As String       'Name of the Database User
Dim sDateTime As String     'Date and Time of the change
'===========================================================================================
'
'   This Audit Trail will track changes to existing records.
'   In the "Before Update" event of the FORM enter the following:
'
'       Call AuditTrail(Me.Form, [RecordID])
'
'   Make sure to create a table called "tbl_AuditLog" and have the following fields:
'   (A table will be created automatically if it does not exist)
'
'       1. RecordID (This is a unique number)
'       2. txt_Table (This is the table where the record was changed)
'       3. lng_TblRecord (This is the RecordID number from the record being changed)
'       4. txt_Form (This is the form being used to edit the record)
'       5. txt_Control (This is the data entry control (field) that was edited
'       6. mem_From (This is the original data in the control (field)
'       7. mem_To (This is what the original data was changed to)
'       8. txt_PCName (This is the name of the PC used to edit the record)
'       9. txt_PCUser (This is the name of the user logged onto the PC)
'       10. txt_DBUser (This is the name of the person looged on to the databse if used)
'       11. dat_DateTime (This is the date and time the record was edited.)
'
'
'   The inspiration behind this code is from:
'       1. support.microsoft.com/default.aspx?scid=kb;en-us;197592
'       2. access-programmers.co.uk/forums/showthread.php?t=44231
'
'
'   Be sure to enable the "Microsoft DAO 3.6 Object Library" Reference
'
'============================================================================================
 
 
Public Function AuditTrail(frm As Form, lngRecord As Long)
On Error GoTo Error_Handler
 
    '----------------------------------------------------------------------
    '   Skips this procedure if a new record is being entered in the form
    '----------------------------------------------------------------------
    'If frm.NewRecord = True Then
    '    Exit Function
    'End If
 
    '----------------------------------------------------------------------
    '   Checks to see if the tbl_AuditLog Exists
    '   Creates the table if it does not exist
    '----------------------------------------------------------------------
    Set dbs = CurrentDb
    dbs.TableDefs.Refresh
 
    sAuditTable = "tbl_AuditLog"
    On Error Resume Next
    If IsNull(dbs.TableDefs(sAuditTable)) Then
        'Table does not exist
        On Error GoTo Error_Handler
        sSQL = "CREATE TABLE tbl_AuditLog([RecordID] COUNTER PRIMARY KEY, [txt_Table] TEXT(50), [lng_TblRecord] LONG, " & _
                "[txt_Form] TEXT(50), [txt_Control] TEXT(50), [mem_From] MEMO, [mem_To] MEMO, [txt_PCName] TEXT(50), " & _
                "[txt_PCUser] Text(50), [txt_DBUser] Text(50), [dat_DateTime] DATETIME);"
        DoCmd.SetWarnings False
        DoCmd.RunSQL sSQL
        DoCmd.SetWarnings True
    Else
        'Table Exists. Do Nothing
        On Error GoTo Error_Handler
 
    End If
    Set dbs = Nothing
 
 
 
    '----------------------------------------------------------------------
    '   Runs through each control on the form and checks for edits/changes
    '----------------------------------------------------------------------
    For Each CTL In frm
 
        Select Case CTL.ControlType     'Only checks data entry type controls.
            Case acTextBox, acComboBox, acListBox, acOptionGroup
 
                sFrom = Nz(CTL.OldValue, "Null")
                sTo = Nz(CTL.Value, "Null")
 
                If sFrom <> sTo Then
 
                    '-----------------------------------
                    '   Gets the required Info
                    '-----------------------------------
                    sTable = frm.RecordSource
                    sPCName = Environ("COMPUTERNAME")
                    sPCUser = Environ("Username")
                    sDBUser = "Me"      'Get Username from the database login
                    sDateTime = Now()
                    sSQL = "INSERT INTO tbl_AuditLog ([txt_Table], [lng_TblRecord], [txt_Form], [txt_Control], " & _
                           "[mem_From], [mem_To], [txt_PCName], [txt_PCUser], [txt_DBUser], [dat_DateTime]) " & _
                           "VALUES ('" & sTable & "', '" & lngRecord & "', '" & frm.Name & "', " & _
                           "'" & CTL.Name & "', '" & sFrom & "', '" & sTo & "', '" & sPCName & "', " & _
                           "'" & sPCUser & "', '" & sDBUser & "', '" & sDateTime & "')"
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL sSQL
                    DoCmd.SetWarnings True
 
                End If
        End Select
    Next CTL
 
Error_Handler_Exit:
   Exit Function
Error_Handler:
    MsgBox ("Error No: " & Err.Number & vbCrLf & vbCrLf & "Error Description: " & Err.Description)
    Err.Clear
    Resume Error_Handler_Exit
End Function

If I add in the following, to the Error Handler code, the error doesn't happen, but the changes aren't rceorded in the audit table either...

Code:
If Err.Number = 3251 Then 'Operation is not supported for this type of object.
  Exit Function
End If

I could really do with some gentle guidance, or a full on verbal whooping (former is preferred).

Thanks lovely people!
 

Users who are viewing this thread

Top Bottom