Ending a routine

  • Thread starter Thread starter art
  • Start date Start date
A

art

I want to present a messagebox to the user that allows him
to cancel and get completely out of the "program". Exit
Sub is not enough because the messagebox has been called
from another sub. How do I do this?
 
I want to present a messagebox to the user that allows him
to cancel and get completely out of the "program". Exit
Sub is not enough because the messagebox has been called
from another sub. How do I do this?

Change the sub with the msgbox into a function, and instead of just
calling it from the other sub, check its return value, which you set
based on the return value of the msgbox. Here's an example:
Sub bar()
If Not foo Then Exit Sub
'or, assigned to a variable:
y = foo
If Not y Then Exit Sub 'or if y=false
End Sub

Function foo() As Boolean
x = MsgBox("blah", vbOKCancel)
If x = vbCancel Then
foo = False
Exit Function
End If
'...
foo = True
End Function
 
Back
Top