Hi all
(Access 2002 VBA)
I’ve got a need to catch errors that are raised from some code that is evaluated with eval. Here’s some sample code that displays my problem.
Function testFn() Err.Raise 100 testFn = 5 ‘Correctly, this doesn’t get evaluated End Function Sub testEval() On Error GoTo ErrorHandler Dim result As Integer ‘Err.Raise 100 ‘If this was here, works as expected result = Eval(“testFn()”) ‘This should raise error, but it is unhandled Debug.Print “Result is”, result Exit Sub ErrorHandler: ‘Should end up here, but doesn’t Debug.Print “Error”, Err.Number, “handled” End Sub
The problem is that the error raised should be caught by the ErrorHandler, but it isn’t. Instead, VBA displays the familiar ‘run time error’.
It doesn’t matter what my Tools>Options>General>Error trapping setting is.
Should I be able to catch a raised error from eval’d code? If not, what are my other options?
Naturally, MS documentation is of zero help.
Thanks for any ideas.
Peter