Consulting

Results 1 to 3 of 3

Thread: Solved: Error Handling Question

  1. #1

    Solved: Error Handling Question

    Is it possible to Exit sub from another Sub? In my Sub "DataTable" I call a Sub named "CorrectTimepoint". If the error "No data to parse" happens, I want to have a message box appear and both routines to halt.

    Thanks,
    Kathyb0527

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub DataTable()

    'some logic

    If Not CorrectTimepoint Then Exit Sub

    'more logic
    End Sub

    Function CorrectTimepoint() As Boolean

    'some logic

    'if something happens then

    MsgBox "No data to parse"

    CorrectTimepoint = False

    Exit Function

    'more logic

    CorrectTimepoint = True

    End Function
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Not sure which error number that is. If you want to End all subs then use End.

    e.g.
    [vba]Sub DataTable()
    CorrectTimepoint 0
    MsgBox "CorrectTimepoint generated no error."
    End Sub

    Sub CorrectTimepoint(aNumber As Long)
    Dim Msg As String
    On Error GoTo ErrMsg
    If aNumber <> 0 Then Err.Raise aNumber
    MsgBox "aNumber=0 so no error was generated."

    Exit Sub
    ErrMsg:
    Msg = "Error # " & Str(Err.Number) & " was generated by " _
    & Err.Source & Chr(13) & Err.Description
    MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
    End
    End Sub[/vba]
    There are at least 2 kb and article entries on error handling. http://vbaexpress.com/forum/showthread.php?t=24173
    http://vbaexpress.com/forum/showthread.php?t=21904

Posting Permissions

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