By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,558 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,558 IT Pros & Developers. It's quick & easy.

Stop while...wend statement on Unload Userform

P: 1
Hi,

I have created a command button that validates information on the userform. For example:

While textbox1.Text = ""
MsgBox "Please enter the reference of the document.", vbExclamation, "Document Reference"
userform1.Hide
userform1.Show
Wend

And i have another command button to unload the userform.

Private Sub exit_Click()
Unload userform1
End Sub

but when i click it, it keeps executing the while of the validation botton. How can i stop that and just Unload the userform1.

Thanks.
Sep 10 '07 #1
Share this Question
Share on Google+
3 Replies


kadghar
Expert 100+
P: 1,295
change WHILE for IF
and WEND for END IF

Remember WHILE, FOR and DO will make loops until the code stop them.
IF will only make the comparision once
Sep 10 '07 #2

Robbie
100+
P: 180
Hi,

but when i click it, it keeps executing the while of the validation botton. How can i stop that and just Unload the userform1.
- Add a variable at form-level which is a boolean type, called StopValidating
- Change the While line to include and StopValidating=False
- In the code for when unloading the form, set StopValidating to True. That way, the While condition will turn out FALSE and so the loop will break.

Hope it helps! =D
Sep 10 '07 #3

kadghar
Expert 100+
P: 1,295
- Add a variable at form-level which is a boolean type, called StopValidating
- Change the While line to include and StopValidating=False
- In the code for when unloading the form, set StopValidating to True. That way, the While condition will turn out FALSE and so the loop will break.

Hope it helps! =D
in that case dont forget to put DoEvents inside the loop
Sep 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.