I am using a variation of Allen Browne's global error handler found at http://allenbrowne.com/ser-23a.html to catch most of my database errors. Errors that I have planned for are trapped with a custom error message while those that I have not planned for are logged to a error table.
Now take a look at the following code and then I will explain the problem I am having.
Code:
' *****************************************
' Returns the user to the main switchboard.
' *****************************************
Private Sub btnGoHome_Click()
On Error GoTo ErrorHandler
DoCmd.Close , ""
Forms!SwitchboardLCDB.Visible = True
Exit_ErrorHandler:
Exit Sub
ErrorHandler:
'MsgBox Err.Number & " - " & Err.Description
Call ErrorLog(Err.Number, Err.Description, Me.Name)
Resume Exit_ErrorHandler
End Sub
If I open the database and bypass SwitchboardLCDB (this is done by holding down the SHIFT key while double clicking on the db icon) and then open the form associated with the above btnGoHome_Click() and then close it, I get
Code:
Run-time error: '5': Invalid procedure call or argument
When I select debug from the error pop-up message, I am taken to this line of code
Code:
Call ErrorLog(Err.Number, Err.Description, Me.Name)
Now if I unRemark MsgBox Err.Number & " - " & Err.Description and Remark Call ErrorLog(Err.Number, Err.Description, Me.Name) I get the following error message
Code:
2450 - Microsoft Office can't find the form 'SwitchboardLCDB' referred to in a macro expression or Visual Basic code
Now this error I understand as the SwitchboardLCDB was never opened so its visible property cannot be set to True.
What I don't understand is why my call to ErrorLog is not trapping that error as I have it listed as a trappable error in my Select Case statement. Also I don't understand why I am getting a run time 5 error on the Call ErrorLog and a error 2450 on the msgbox error.
You may be asking your self why I am opening the database and bypassing the main switchboard. when I conduct maintenance on the database, I bypass most of the forms that are intended for use by the database users. As such I am trying to trap all the error messages that result from not using the forms to navigate the database.
Now I know that I could just put a select case statement in the errorhandler for the btnGoHome_Click() event that traps the 2450 error but I would prefer to only have to create one case select statement in one location, the global error handler module, and not on the close event of every form that leads back to the main switchboard.
any suggestions?
Thanks in advance,
Sean