Have a called function stop the originial function

ilya2004

Board Regular
Joined
Mar 17, 2011
Messages
135
I have a function which at one step calls a userform. I want to set it up such that if the person hits cancel in the userform, it will close the form and stop the original function which called it as well. What would be the code for the second of those?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Add a public boolean variable to your form called Cancelled (or better still a Property procedure) that gets set to true if the form is cancelled (and make sure the form gets hidden, not unloaded. The calling routine can then check the value of Cancelled and exit if appropriate.
 
Upvote 0
I tried to use the public variable, but for some reason it is not passing it from the form to the original routeen that called it, so it keeps on running.
 
Upvote 0
Did you ensure the form gets hidden and not unloaded?
 
Upvote 0
Example:

Code:
'General module
 
Function Test()
    With UserForm1
        .Show
        If .Cancelled Then
            MsgBox "Cancelled"
            Unload UserForm1
            Exit Function
        Else
            MsgBox "Not Cancelled"
        End If
    End With
End Function
 
'UserForm module
 
Public Cancelled As Boolean
 
Private Sub cmdCancel_Click()
    Cancelled = True
    Me.Hide
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top