13 - Type Mismatch

KevCB226

Registered User.
Local time
Today, 19:40
Joined
Oct 20, 2005
Messages
24
Audit Trail doesn't pick up changes in subform

Hi

I posted this on the end of the audit trail thread but nobody was really looking at it. I have used the script for the audit trail, and when I start changing any of the records, it comes up with the error:

13 - Type Mismatch

When I ctrl - break, and debug, it highlights the last line of the script:

Code:
On Error GoTo Form_BeforeUpdate_Err
    
    Call Audit_Trail(Me)
    
Form_BeforeUpdate_Exit:
    Exit Sub
    
Form_BeforeUpdate_Err:
    MsgBox Err.Number & " - " & Err.Description
    [COLOR=Red]Resume Form_BeforeUpdate_Exit[/COLOR]

Anyone any ideas on what is happening?
 
Last edited:
I cannot claim familiarity with the "Audit Trail" code, but it is highlighting that line because that is the line of code that would be executed next, if the procedure were allowed to continue to run (i.e. if you hadn't Debugged, or if now that you are in debug, you were to press F8, or choose Run from the menu, etc.

If there is no error handling enabled inside the Audit_Trail procedure, if an error happens in there it will be passed up the call stack to the calling procedure, in this case, from the looks of things probably "Form_BeforeUpdate" and would activate that procedure's error handling if it were enabled (which it obviously is).

To get closer to the cause, enable error handling in the Audit_Trail procedure, similar to what you have here, if you like. Don't forget the On Error Goto.... statement at the top of the procedure. I typically do something like

Code:
Option Explicit

Const mConSzModName As String = "frmThisFormsName"
Dim mSzMsgTitle As String
Dim mSzMsgPrompt As String


Private Sub cmdOK_Click()
    On Error GoTo cmdOK_Click_err
    Const conszProcedureName As String = "cmdOK_Click"

    'do some stuff
    'say an error happens here
    'when I force it to Resume Next during debug this line will highlight telling me the problem was with the line above
    
cmdOK_Click_Exit:
    Exit Sub
    
cmdOK_Click_err:
        mSzMsgTitle = "Error"
        mSzMsgPrompt = "An unexpected error has occurred." _
        & vbCrLf & "Please record the circumstances of the error, and the EXACT details below, and report this error to your manager." _
        & vbCrLf & vbCrLf & mConSzModName & "!" & conszProcedureName _
        & vbCrLf & vbCrLf & "Error number : " & Err.Number _
        & vbCrLf & "Error Description : " & Err.Description _
        & vbCrLf & "Error Source : " & Err.Source
    End If
    MsgBox mSzMsgPrompt, vbExclamation + vbOKOnly, mSzMsgTitle
    Resume cmdOK_Click_Exit
    Resume Next  'this is here just for use in setting next statement during debug
End Sub

Note the Resume Next as the very last line before End Sub, and after the other Resume statement. In the ordinary course of execution the Resume Next would never be triggered, but when I go into debug, I set that line to be the next statement to run, then run it, and see where it takes me. That tells me where the error occurred. Just reflecting on it now, I suppose I could use Resume, instead of Resume Next, but that is just the way I have it set up.

HTH

Regards.

John
 
Thanks for the reply, as I'm not too familiar with vba I'll take that into consideration if I come across any problems in the future.

I've manage to sort it out, I didn't read the thread completely and missed out setting the form as an arguement of the Function. :rolleyes:

Although I still can't get it to pick up changes on the subform, which is in a tab control. :(
 
Now that you mention it Pat, I think having been 'driven nuts' in the past by using 'Break On All Errors' and forgetting to set it back, may be why I now use the set up I described...
 
KevCB226 said:
Thanks for the reply, as I'm not too familiar with vba I'll take that into consideration if I come across any problems in the future.

I've manage to sort it out, I didn't read the thread completely and missed out setting the form as an arguement of the Function. :rolleyes:

Although I still can't get it to pick up changes on the subform, which is in a tab control. :(
Go back to the Audit Trail thread and re-read the posts the other users have posted in regards to using the Audit Trail code with subforms. I have yet to need the code for a subform so I can not help with that but I do believe that your answer is buried within the Audit Trail thread.
 
Go back to the Audit Trail thread and re-read the posts the other users have posted in regards to using the Audit Trail code with subforms. I have yet to need the code for a subform so I can not help with that but I do believe that your answer is buried within the Audit Trail thread.
Yup, that would be correct...check page 6. I found that one buried and put it on there myself and it works fantastico!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom