Results 1 to 5 of 5
  1. #1
    PhilaG is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    1

    Audit Trail database

    Good Day,



    We are trying to develop a functionality on our system/ Database.

    The user is looking for audit report, which will audit everything that any user is doing on the system or database. because the system is used by many users, now it is difficult to track how did what. I have tried to use some code that i found on the internet but never worked. tried to follow some tutorial on internet with on success.
    Code:
    Sub AuditChanges(IDField As String, UserAction As String)
        On Error GoTo AuditChanges_Err
        Dim cnn As ADODB.Connection
        Dim rst As ADODB.Recordset
        Dim ctl As Control
        Dim datTimeCheck As Date
        Dim strUserID As String
        Set cnn = CurrentProject.Connection
        Set rst = New ADODB.Recordset
        rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
        datTimeCheck = Now()
        strUserID = Environ("USERNAME")
        Select Case UserAction
            Case "EDIT"
                For Each ctl In Screen.ActiveForm.Controls
                    If ctl.Tag = "Audit" Then
                        If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
                            With rst
                                .AddNew
                                ![DateTime] = datTimeCheck
                                ![UserName] = strUserID
                                ![FormName] = Screen.ActiveForm.Name
                                ![Action] = UserAction
                                ![RecordID] = Screen.ActiveForm.Controls(IDField).Value
                                ![FieldName] = ctl.ControlSource
                                ![OldValue] = ctl.OldValue
                                ![NewValue] = ctl.Value
                                .Update
                            End With
                        End If
                    End If
                Next ctl
            Case Else
                With rst
                    .AddNew
                    ![DateTime] = datTimeCheck
                    ![UserName] = strUserID
                    ![FormName] = Screen.ActiveForm.Name
                    ![Action] = UserAction
                    ![RecordID] = Screen.ActiveForm.Controls(IDField).Value
                    .Update
                End With
        End Select
    AuditChanges_Exit:
        On Error Resume Next
        rst.Close
        cnn.Close
        Set rst = Nothing
        Set cnn = Nothing
        Exit Sub
    AuditChanges_Err:
        MsgBox Err.Description, vbCritical, "ERROR!"
        Resume AuditChanges_Exit
    End Sub
    I would appreciate you assistance
    Thank you
    Last edited by orange; 11-04-2020 at 12:07 PM. Reason: added code tags

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Please go back to your post (if it's not too late) and encapsulate that in code tags, and use these tags and proper indenting for anything more than a few lines (# on thread toolbar). I might not be able to help with the problem, but I can at least help you to help others make sense of that. I won't even try (I know, I'm old and intolerant but that's the way it is).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You may get some ideas from this thread. (data macro based)
    Or this one (forms based).
    You might also want to review SQL server Express (free) as your back end database.

    Whatever you decide, take the time to test thoroughly before putting any audit function into production if you are dependent on audit records.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You might also see Creating an Audit Log by Allen Browne ( article and code)

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    'never worked' doesn't help us to help you. You need to provide the context of when you run this code, the nature of the form (single/continuous/datasheet), whether the form has subforms, any error messages etc.

    and when you step through the code - do you see the values you expect to see?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Audit Trail Help
    By HelpDesk in forum Access
    Replies: 9
    Last Post: 08-07-2015, 06:13 AM
  2. Audit Trail
    By zburns in forum Access
    Replies: 4
    Last Post: 07-27-2015, 08:49 AM
  3. Replies: 2
    Last Post: 04-16-2014, 11:17 AM
  4. Replies: 2
    Last Post: 02-09-2013, 12:39 PM
  5. Audit Trail
    By bigroo in forum Programming
    Replies: 4
    Last Post: 02-22-2012, 07:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums