Results 1 to 2 of 2
  1. #1
    jabrjo is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    33

    Simple Audit Table - tracking changes to combo and list boxes

    Hello,



    I recently created an audit table using the code from this link: http://www.techrepublic.com/article/...o-access-data/. Its working well for a majority of the edits, however, its does not track changes/edits made within combo or list boxes. Does anyone have any simple suggestions on how I can change this code to reflect edits made within combo or list boxes? I am an VBA rookie so the easier the better...

    The code in the link is also listed below

    Code:
    Const cDQ As String = """"Sub AuditTrail(frm As Form, recordid As Control)
      'Track changes to data.
      'recordid identifies the pk field's corresponding
      'control in frm, in order to id record.
      Dim ctl As Control
      Dim varBefore As Variant
      Dim varAfter As Variant
      Dim strControlName As String
      Dim strSQL As String
      On Error GoTo ErrHandler
      'Get changed values.
      For Each ctl In frm.Controls
        With ctl
        'Avoid labels and other controls with Value property.
        If .ControlType = acTextBox Then
          If .Value <> .OldValue Then
            varBefore = .OldValue
            varAfter = .Value
            strControlName = .Name
            'Build INSERT INTO statement.
            strSQL = "INSERT INTO " _
               & "Audit (EditDate, Username, RecordID, SourceTable, " _
               & " SourceField, BeforeValue, AfterValue) " _
               & "VALUES (Now()," _
               & cDQ & Environ("username") & cDQ & ", " _
               & cDQ & recordid.Value & cDQ & ", " _
               & cDQ & frm.RecordSource & cDQ & ", " _
               & cDQ & .Name & cDQ & ", " _
               & cDQ & varBefore & cDQ & ", " _
               & cDQ & varAfter & cDQ & ")"
            'View evaluated statement in Immediate window.
            Debug.Print strSQL
            DoCmd.SetWarnings False
            DoCmd.RunSQL strSQL
            DoCmd.SetWarnings True
          End If
        End If
        End With
      Next
      Set ctl = Nothing
      Exit Sub
    
    ErrHandler:
      MsgBox Err.Description & vbNewLine _
       & Err.Number, vbOKOnly, "Error"
    End Sub
    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe:

    If .ControlType = acTextBox Or .ControlType = acComboBox Or .ControlType = acListBox Then


    Note that I am guessing about acComboBox and acListBox - these might not be correct constants.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-22-2014, 08:03 AM
  2. Audit Tracking
    By LisaEllen in forum Access
    Replies: 12
    Last Post: 09-03-2013, 05:22 PM
  3. Replies: 2
    Last Post: 02-09-2013, 12:39 PM
  4. Combo/List Boxes
    By refryguy in forum Forms
    Replies: 3
    Last Post: 07-28-2011, 01:34 PM
  5. Simple list/combo search fails
    By Dega in forum Forms
    Replies: 4
    Last Post: 02-08-2010, 08:39 AM

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