469,913 Members | 2,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

Stop unloading the form

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
2 3865
missinglinq
3,532 Expert 2GB
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
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.

Similar topics

1 post views Thread by LilleSkutt | last post: by
9 posts views Thread by Rom Marshall | last post: by
2 posts views Thread by Guru Prasad | last post: by
10 posts views Thread by peter hansen | last post: by
3 posts views Thread by Glenn | last post: by
reply views Thread by ibenc | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.