Results 1 to 6 of 6
  1. #1
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169

    Audit trail question

    I am using the following code obtained from http://support.microsoft.com/kb/197592 to create an audit trail. I would like to have the audit trail field that is created not print the statement "previous value was blank." for new records. The form I want to attach this module to has over 30 fields which would create a lot of pointless verbiage in this field. I think it should be obvious for a new record that all the fields were previously blank. All I would want to print in the audit trail is the "new record" portion. Can anybody help me with tweaking this code to accomplish this? Thanks!



    Code:
    Function AuditTrail()
    On Error GoTo Err_Handler
     
        Dim MyForm As Form, C As Control, xName As String
        Set MyForm = Screen.ActiveForm
     
        'Set date and current user if form has been updated.
        MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
        "Changes made on " & Date & " by " & CurrentUser() & ";"
     
        'If new record, record it in audit trail and exit sub.
        If MyForm.NewRecord = True Then
            MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
            "New Record """
        End If
     
        'Check each data entry control for change and record
        'old value of Control.
        For Each C In MyForm.Controls
     
        'Only check data entry type controls.
        Select Case C.ControlType
            Case acTextBox, acComboBox, acListBox, acOptionGroup
                ' Skip Updates field.
                If C.Name <> "Updates" Then
     
                ' If control was previously Null, record "previous
                ' value was blank."
                    If IsNull(C.OldValue) Or C.OldValue = "" Then
                        MyForm!Updates = MyForm!Updates & Chr(13) & _
                        Chr(10) & C.Name & "--previous value was blank"
     
                    ' If control had previous value, record previous value.
                    ElseIf IIF(IsNull(C.Value),"",C.Value) <> C.OldValue Then
                        MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
                        C.Name & "==previous value was " & C.OldValue
                    End If
                End If
            End Select
        Next C
     
    TryNextC:
        Exit Function
     
    Err_Handler:
    If Err.Number <> 64535 Then
    MsgBox "Error #: " & Err.Number & vbCrLf & "Description: " & Err.Description
    End If
    Resume TryNextC
    End Function

  2. #2
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    The easiest approach is to simply rem out (put single apostrophe as first character of the line telling vba to ignore the line) the lines shown below:

    If IsNull(C.OldValue) Or C.OldValue = "" Then
    ' MyForm!Updates = MyForm!Updates & Chr(13) & _
    ' Chr(10) & C.Name & "--previous value was blank"

    ' If control had previous value, record previous value.
    ElseIf IIF(IsNull(C.Value),"",C.Value) <> C.OldValue Then
    MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
    C.Name & "==previous value was " & C.OldValue
    End If

  3. #3
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Thanks Dave. That works, but it also removes the previous value was blank for existing records that have a field updated from blank to some value. Is there a way to get the message to print for existing records when applicable but not the new records?

  4. #4
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Actually, I think I found the answer. I put an Exit Function command as shown below and that seems to work.

    Code:
    'If new record, record it in audit trail and exit sub.
        If MyForm.NewRecord = True Then
            MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
            "New Record """
             Exit Function
        End If

  5. #5
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    Good. Presume you're using workgroup for 2003 so that CurrentUser means something.

    MS removed workgroups from 2007, but I have used 2007 program against 2003 file format w/secure workgroups OK.

  6. #6
    jpkeller55 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    169
    Yes, that is correct. The currentUser is the persons network ID name.

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

Similar Threads

  1. audit Log
    By mwabbe in forum Access
    Replies: 42
    Last Post: 05-30-2011, 07:23 AM

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