Ending a routine

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?
 
A

Auric__

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top