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
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
[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
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