Results 1 to 11 of 11
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    General Error Control

    Good Morning!

    I'm looking for a way to control errors within a userform in an excel spreadsheet. This userform refers to MOUNTIAINS of code. I would like to setup a message box which returns:

    Your application has returned an error, please contact your technical support group.

    I don't want the 'Continue, End, Debug, Help ' window to appear at all. Any ideas?
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: General Error Control

    Hi Drk,
    What you need is a routine within your code to produce your message box. How exactly you do this depends on your code. You can either have an error handler within each sub like this:
    Private Sub Whatever()
    On Erro Goto err_handler
    your code goes here
    exit sub
    err_handler:
    msgbox "Your application has returned an error, please contact your technical support group. "
    end sub
    or you can write a separate procedure like:
    Sub ErrorHandle()
    msgbox "Your application...."
    end sub
    and call it from within the err_handler: bit of each routine. Either way each routine should set any Object variables you've created to Nothing before exiting.
    I hope that's clear (it's probably a bit rambling!) - any questions please repost.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    Makes sense, to a degree...

    but i'm having problems..

    I've written a sub... (yellow one at that..) [img]/w3timages/icons/doh.gif[/img]
    ***CODE START***
    Sub ErrorHandle()
    MsgBox ("Your application has returned an error, please contact your technical support group. ")
    End Sub
    ****CODE END****
    Then incorporated the following line into my code peices:
    ***CODE START***
    On Error GOTO ErrorHandle()
    ****CODE END****

    It's telling me that ErrorHandle() is not defined.. any ideas?
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    err.. label not defined..
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  5. #5
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    I think all I need here is a brief usage example of GOTO. VBA Help seems to relate it only to a range within the workbook. How can I define a reference in the code, and later return to that code via a GOTO command?

    Thanks!
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  6. #6
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    eastern Connecticut, Connecticut, USA
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    Taken From the Visual Basic Excel Reference -- Office97 SR2

    There are two references to 'goto' in the index: "Goto" and "GoTo". The second one has a subreference called:
    Control Flow Keyword Summary.

    The GoTo keyword is shown in the first Action grouping called Branch. Going to the GoTo statement page you'll find that the statement must reference a valid label or line number that must be within the procedure that contains the GoTo statement.

  7. #7
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    How do I define a label?
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  8. #8
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    eastern Connecticut, Connecticut, USA
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    Again, from the VBE Help...

    line label

    Used to identify a single line of code. A line label can be any combination of characters that starts with a letter and ends with a colon (. Line labels are not case sensitive and must begin in the first column.

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    I can read the helpfile...

    i've placed the following code above all others:

    errhandle:
    msgbox ("A code error has occured, contact your technical support group.")

    yet I am still getting the 'label not defined' error when I place the following:

    on Error goto errhandle

    in the code.. what am I doing wrong?
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  10. #10
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    The Label used in a GoTo MUST be in the same procedure as the GoTo that refers to it. A GoTo is not a Call, so you can not return to where you came from, it is a permanent transfer of control to the label location.

    Also, when the error condition is raised, the program is put into a special condition and can not do many things. You should always end an error handler with a Resume statement. To catch all errors, you are also going to need an On Error statement in every Sub or Function procedure. It would look something like this:

    <pre>Private Sub MySub()
    On Error GoTo ErrHandler

    other code here

    Xit:
    Exit Sub

    ErrHandler:
    Call MyErrorMessage
    Resume Xit
    End Sub
    </pre>

    Legare Coleman

  11. #11
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General Error Control

    There it is.. Thanks again Legare!
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

Posting Permissions

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