Results 1 to 3 of 3

Thread: How to avoid repetition - "On error goto" command

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Hi, everybody!

    I’m dealing with errors using the command:
    =====================
    On error goto MyError
    =====================
    but I have the same module to deal with errors from various buttons.
    I’ve tried to create a private sub called Private Sub MyError() and to call it from the various buttons, using the command:
    =====================
    On error call MyError
    =====================
    but it doesn’t work. I’ve tried to create just a Label called MyError, outside any Private Sub, but it doesn’t work either.
    If I use the command - On Error Resume Next – it works ok with the error, but I’d like to be able to send the user a Msgbox also.
    Any ideas on how to avoid creating a MyError label with the same commands in all the buttons click events?
    Thanks in advance,
    Roselene



  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    In MyError in each routine, call a common error routine like so...

    MyError:
    If Err.Nbr > 0 Then
    MyCommonErrorRoutine
    End If

    In my code I pass the name of the calling routine to the common error routine so that it can be displayed within the error message.

    ------------------
    Marty

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Martin,

    Thanks very much! It works!
    I'll try to pass some information of the calling routine to the common error in order to let the user know about what he should do.

    Best regards,
    Roselene

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width