Results 1 to 5 of 5

Thread: on error

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    on error

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     On Error GoTo ErrorHandler
    4.  
    5. code here
    6. code here
    7. call function1
    8. call function2
    9.  
    10. ErrorHandler:
    11.     MsgBox ErrorPrefix & "Error id: " & err & ", " & Error, vbCritical, version & " - error!"
    12. end sub

    function1 and function2 have error handling like that too

    but whe i start my form up, it keeps msgboxing but the errorid and message are blank

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: on error

    post function code

  3. #3
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: on error

    Its cos you are missing the EXIT SUB..

    do it like this:

    Private Sub Form_Load()

    On Error GoTo ErrorHandler

    code here
    code here
    call function1
    call function2

    Exit Sub

    ErrorHandler:
    MsgBox ErrorPrefix & "Error id: " & err & ", " & Error, vbCritical, version & " - error!"
    end sub

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: on error

    Put Exit Sub before the ErrorHandler. You see a blank Errnumber and description because there is no error, however you are still executing this statement
    VB Code:
    1. MsgBox ErrorPrefix & "Error id: " & err & ", " & Error, vbCritical, version & " - error!"
    Your code should be like this
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.         On Error GoTo ErrorHandler
    4.  
    5.     code here
    6.     code here
    7.     call function1
    8.     call function2
    9.     'Make sure we don't execute the error handling code if there is no error
    10.     Exit Sub
    11.     ErrorHandler:
    12.         MsgBox ErrorPrefix & "Error id: " & err & ", " & Error, vbCritical, version & " - error!"
    13.     end sub
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: on error

    ahh yeaa thanks, thats sorted it.

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