Results 1 to 3 of 3
  1. #1
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42

    Audit Trail

    Hi everybody, I'm developing an audit trail for the first time. It works when I add a new record but not when I change anything. By works I mean it adds the record to the audit table.


    Here is some code that hopefully somebody can spot where I'm going wrong.


    Dim DB As Database
    Dim rst As Recordset
    Dim clt As Control
    Dim UserLogin As String


    Set DB = CurrentDb
    Set rst = DB.OpenRecordset("select * from tblAuditTrail", adOpenDynamic)


    UserLogin = Environ("Username")
    Select Case UserAction






    Case "Edit"


    For Each clt In Screen.ActiveForm.Controls
    If (clt.ControlType = acTextBox _
    Or clt.ControlType = acComboBox) Then
    If Nz(clt.Value) <> Nz(clt.OldValue) Then

    With rst
    .AddNew
    ![DateTime] = Now()
    !UserName = UserLogin
    !FormName = Screen.ActiveForm.Name
    !Action = UserAction
    !RecordID = Screen.ActiveForm.Controls(RecordID).Value
    !FieldName = clt.ControlSource
    !OldValue = clt.OldValue
    !NewValue = clt.NewValue
    .Update


    End With
    End If
    End If


    Next clt
    End Select




    'tblAuditTrail
    'AuditTrailID
    'DateTime
    'UserName
    'FormName
    'Action
    'RecordID Number
    'FieldName
    'OldValue
    'NewValue


    'frmEmployees
    'BeforeUpdateEvent


    If Me.NewRecord Then
    Call AuditChanges("EmpID", "New")
    Else
    Call AuditChanges("EmpID", "Edit")
    End If


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    Ok, issues resolved. Minor 3 character mistake in code.
    Thanks,

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

Similar Threads

  1. Audit Trail
    By conjohn in forum Access
    Replies: 1
    Last Post: 01-21-2020, 10:16 AM
  2. Audit Trail
    By zburns in forum Access
    Replies: 4
    Last Post: 07-27-2015, 08:49 AM
  3. Having an audit trail
    By ryanmce92 in forum Modules
    Replies: 5
    Last Post: 06-03-2015, 02:29 PM
  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

Tags for this Thread

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