Results 1 to 2 of 2
  1. #1
    usmcgrunt's Avatar
    usmcgrunt is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    Just outside the gates of freedom
    Posts
    71

    Global Error Handler Issue

    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

  2. #2
    usmcgrunt's Avatar
    usmcgrunt is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    Just outside the gates of freedom
    Posts
    71
    Well immediately after posting this thread I solved the problem. The reason why I was getting the run time error 5 on my ErrorLog call was because I was closing the btnGoHome_Click() form before I was trying to set the SwitchboardLCDB form to visible. As such, the Call to ErrorLog could not get Me.Name. Once I swapped the close and set to visible lines, the Call to ErrorLog worked and trapped the error with my custom message.

    I hate it when I solve a problem right after I have spent so much time trying to write out an explanation of the problem. So consider this post solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Global Property Changes
    By ajetrumpet in forum Code Repository
    Replies: 2
    Last Post: 08-07-2012, 10:31 PM
  2. Username as Global Variable
    By imintrouble in forum Access
    Replies: 3
    Last Post: 10-10-2011, 10:45 AM
  3. Replies: 7
    Last Post: 01-26-2011, 08:31 PM
  4. confusing datatype error issue
    By TheShabz in forum Queries
    Replies: 5
    Last Post: 10-11-2010, 05:14 PM
  5. Help Please - Global Vars
    By graviz in forum Programming
    Replies: 3
    Last Post: 02-18-2010, 10:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums