Results 1 to 2 of 2
  1. #1
    jtm013 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    117

    Problem with Audit trail module

    Hello,



    I have a database which is set up to record changes to an audit trail.
    I have had no problems with this feature and it has been in use for approximately 6 months now.
    The methodology is simple a tag of "Audit" is placed on each field I want changes record for, in the before update event I call the audit procedure and it writes the old and new value to an audit trail table.

    Recently this has started throwing an overflow error and I cannot figure out why.
    I have listed the code below and made red/bold the code segment which access tells me is producing the overflow error.

    Code:
    Sub AuditChanges(IDField 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
        Dim strCompID As String
        Set cnn = CurrentProject.Connection
        Set rst = New ADODB.Recordset
        rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
        datTimeCheck = Now()
        strUserID = Environ("USERNAME")
        strCompID = Environ("ComputerName")
        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
                        ![ComputerName] = strCompID
                        ![FormName] = Screen.ActiveForm.Name
                        ![recordID] = Screen.ActiveForm.Controls(IDField).Value
                        ![FieldName] = ctl.ControlSource
                        ![OldValue] = ctl.OldValue
                        ![NewValue] = ctl.Value
                        .Update
                    End With
                End If
            End If
        Next ctl
    '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
    Any and all assistance is appreciated.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try explicitly using the second argument of the Nz function. I think it might be choking on a situation where both are Null.
    See: http://www.techonthenet.com/access/f...dvanced/nz.php

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

Similar Threads

  1. Audit Trail into Subform
    By AdamMVRRS in forum Access
    Replies: 10
    Last Post: 02-07-2014, 10:16 AM
  2. Audit Trail and Reporting
    By CementCarver in forum Programming
    Replies: 2
    Last Post: 05-29-2013, 07:42 AM
  3. Replies: 2
    Last Post: 02-09-2013, 12:39 PM
  4. Audit Trail
    By bigroo in forum Programming
    Replies: 4
    Last Post: 02-22-2012, 07:55 PM
  5. audit trail
    By slimjen in forum Forms
    Replies: 1
    Last Post: 10-13-2011, 01:52 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