1

After recently adding some new VBA code that referred to a control, my code wouldn't run. On investigation, I found the problem was a typo in the code referring to the control: I'd typed it as Me.CheckYearEmd (with an m) rather than Me.CheckYearEnd.

This is now resolved and the code's working fine, but the weird thing is the error didn't trigger my error handling; it just didn't run. My error handling works on a very simple basis:

On Error GoTo ErrHandler

... 'Rest of sub

Exit Sub

ErrHandler:
DoCmd.SetWarnings True
MsgBox "The database has generated an error. Please contact the database administrator, quoting the following error message: '" & Err.Description & "'", vbCritical, "Database Error"

Is there something specific about referring to a control that doesn't exist (as I effectivley did above) that causes it to bypass error handling, and is there a way of catching these errors?

Sinister Beard
  • 3,570
  • 12
  • 59
  • 95

1 Answers1

2

I can't recreate the situation you described. When I misspell a control name in the form's code, running Debug->Compile from the VB Editor's main menu triggers a compile error: "Method or data member not found".

However, if I don't run Debug->Compile and just try to run the form's procedure with the misspelled name, I still get that compile error.

Although I can't duplicate your situation, I'll offer a guess why the procedure's error handler doesn't catch it. The directive, On Error GoTo ErrHandler, traps run-time errors. But the misspelled control name triggers a compile error.

HansUp
  • 95,961
  • 11
  • 77
  • 135
  • 1
    +1 I tested and got a compile error, too. Perhaps @BFDatabaseAdmin should consider a [/decompile](http://stackoverflow.com/a/3268188/2144390)? – Gord Thompson May 23 '13 at 13:59