Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2015
    Posts
    1

    Unanswered: Access VBA Audit Trail Not Working With Nav Bar

    Hi All

    I currently using the code below for an Audit Trail (Not My Coding). The code works in the forms but when I create a navigation bar with all the forms the code doesn't work I get a error saying "Can't find Empolyee ID".

    Can anyone help?


    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

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Where does the code halt, thats the line it faults on. Employee id isn't directly referred to here so either this isn't the code throwing the fault or its diwn to how you have or havent set up tge controls
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,418
    Provided Answers: 7
    "Empolyee ID" is not in the activeForm

    you are trying to tell it

    tell me what has change in the activeform with the controls that have TAG of Audit and the Key record ID is the Empolyee ID
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •