Results 1 to 9 of 9
  1. #1
    rrowsam is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10

    Audit Trail "Type mismatch" error

    Hey everyone. I attempted to use this https://www.fontstuff.com/access/acctut21.htm to create a audit trail in my database.

    However, it will only capture if I delete a record, for all other changes it gives me a "Type mismatch" error.



    Anyone have any ideas on what this means, and how to correct it?

    Thanks!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Are you saying the example database doesn't work? Or code in your db does not work?

    What line triggers error?
    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
    rrowsam is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    The example database works fine.

    I can't tell what line is triggering the error. I'll paste the code I'm using. The error pops up whenever I edit any field on my form.

    Would it be helpful to attache my DB?

    Thanks.

    Code:
    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

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Step debug.

    Attach db if you want. I can look at it.
    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.

  5. #5
    rrowsam is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    Database attached.

    Deleted most items and changed most of the info to gibberish, but still getting the same error.
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Which form - Task List? It opens to DataEntry Yes, only new record entry. What steps should I take to replicate issue?
    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.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    rrowsam,

    Read the thread here for more info on the Audit trail program you are working with.
    Good luck.
    Last edited by orange; 04-29-2019 at 08:24 AM.

  8. #8
    rrowsam is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    Quote Originally Posted by June7 View Post
    Which form - Task List? It opens to DataEntry Yes, only new record entry. What steps should I take to replicate issue?
    Yes, the Task List Form.

    If I change anything (such as assessment type or status) than click out of the row, the error pops up.

    Thanks!

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Form opens to new record row. There is nothing to change. I try the search box with value BFSWERG and this causes all records to display.

    I disable the On Error GoTo, run code. It breaks on line "If Nz(ctl.Value) <> Nz(ctl.OldValue) Then". I place a Debug.Print ctl.Name before that line and find it breaks on: "Assigned To".

    I change that control's tag to "xAudit" so it is ignored and don't get error. So why does this control cause error? I am stumped.
    I also tried Debug.Print for that control Value and OldValue and each of those cause the error. Very odd. None of the other comboboxes have issue.


    Unrelated, but advise not to use spaces nor punctuation/special characters (underscore only exception) in naming convention.
    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: 11
    Last Post: 07-14-2017, 11:13 AM
  2. Replies: 17
    Last Post: 04-28-2017, 09:18 PM
  3. Run time error 13 "type mismatch"
    By CHEECO in forum Access
    Replies: 6
    Last Post: 07-02-2016, 02:59 PM
  4. Audit Trail Code Type Mismatch
    By sstiebinger in forum Programming
    Replies: 9
    Last Post: 04-03-2015, 08:59 AM
  5. Replies: 2
    Last Post: 05-17-2011, 02:40 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