View Full Version : Solved: Error Handling Question
kathyb0527
12-11-2008, 12:06 PM
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
Bob Phillips
12-11-2008, 01:06 PM
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
Kenneth Hobs
12-11-2008, 02:11 PM
Not sure which error number that is. If you want to End all subs then use End.
e.g.
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
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.