View Full Version : Error TRapper Code only running in Debug Mode


gjblackford
11-08-2007, 01:01 AM
Hi,

The function below works fine when I run in Debug mode, but when I run the code normally it fails with an Error 13 - Type Mismatch which the error trapper should stop, I have even added a debug.print statement to see if the Error Trapper is being called and it isn't. I have checked that I am on breaking on unhandled errors, so I am at a loss to why this is happening, does anyone have any ideas


Public Function RefreshContribution()
On Error GoTo RefreshContribution_Error

With Forms(CurrentForm)
MsgBox "point"
If !Contribution < 0 Then
MsgBox "point 1"
!Contribution.BackColor = 128
!Contribution.ForeColor = 16777215
!PercentContribution.BackColor = 128
!PercentContribution.ForeColor = 16777215
Else
MsgBox "point 2"
!Contribution.BackColor = IIf(CurrentForm = "AutoCost", 13434828, 10079487)
!Contribution.ForeColor = 0
!PercentContribution.BackColor = IIf(CurrentForm = "AutoCost", 13434828, 10079487)
!PercentContribution.ForeColor = 0
End If
End With

Exit Function

RefreshContribution_Error:
Debug.Print "Error Handler Reached"

If Err.Number = 13 Then
'ignore - no contribution available
Else
ErrorHandler
End If
End Function


Thanks,


Gavin,

Guus2005
11-08-2007, 02:10 AM
type ctrl-break when you get the error message. It brings you to where the error occures. If not, remove the On Error Goto statement.
Remember that each time a statement is executed, the Error object is set. This menas that a successfull debug.print could reset the error number to 0.