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

Stop unloading the form

P: 15
Hi All,

I have a form in which i have few mandatory fields. Wheneve the user tries to save, i check for these fields and alert them, if thet are empty. I have a CLOSE button in my form and whenever the user clicks the CLOSE button, i ask the user whether he wants to save before closing the form.

On the Form_Unload event, i check whether there are any new changes and if yes, i pompt the user for a save. But if they have not filled any of the mandatory fields and if they press the close button, it alerts asking for a value, but immediately after the alert it closes the form, as it is a FORM_UNLOAD event.

Is there any way to stop unloading the form, if i alert them about a mandatory field. Please note that since the code has grown huge shifting the MANDATORY check block from FORM_UNLOAD event is quite tough. So it would be of much help if you can suggest me on how to stop the FORM_UNLOAD???

Thanks a ton.
Nov 13 '06 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 3,532
Cancel = True in the appropriate spot in your code will will stop the unloading. The following, for example will temporarily halt the unloading, pop up a mewssagebox then continue unloading:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.      Cancel = True
  3.      MsgBox "Can't Leave Yet!"
  4.      Cancel = False
  5. End Sub
Replace the messagebox above with your validation code.
Nov 13 '06 #2

P: 15
Thanks a lot dude. Works out exactly as required. Thanks for the quick response.
Nov 13 '06 #3

Post your reply

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