Quit UserForm and Procedure

M

Maria

Hi,

I have a Procedure and a UserForm.
On the UserForm is the Button "Cancel".
When I click this button I would like to quit
the UserForm AND stop running the other procedure.

Sub test()
' Some Code
Call UserForm1
' Some more Code <-- Do not run when quit UserForm
End Sub

Unfortunately this doesn't work:

Private Sub cmbCancel_Click()
Unload Me
Exit Sub
End Sub

What can I do to really leave both?

Thank you for helping me.
Maria
 
N

N10

IS this also appropriate and is it equivalent


Me.HIDE
Set Userform1 = Nothing

Best N10
 
B

Bob Phillips

NO, the code in the calling procedure still continues after this executed.
 
D

Dave Peterson

I think I'd use a boolean variable and set/check that:

In a General module:

Dim OkToContinue as boolean
Sub test()
' Some Code
oktocontinue = true
Call UserForm1
if oktocontinue = false then
exit sub
end if
' Some more Code <-- Do not run when quit UserForm
End Sub

Unfortunately this doesn't work:

Private Sub cmbCancel_Click()
Unload Me
oktocontinue = false
Exit Sub
End Sub

The End statement may do more than what you want--if you use global variables,
you'll see that they've been reset.
 

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