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

Handling The Close [x] Button Of A Form

Kabyr
P: 29
Hi everyone,
Can someone help me with a procedure to handle the clicked event of the Close button (The [X] button on the top right coner of a VB form. I want to be able to query the users intention for clicking, like: Does he want to save before closing ... instead of just closing the window.

I used a command button to achieve this but I also want to do same for the Close button.
Nov 29 '07 #1

✓ answered by Killer42

The details will depend on what version of VB you're using.

In VB6 you would use the form's QueryUnload and/or Unload events.

Share this Question
Share on Google+
13 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Hi everyone,
Can someone help me with a procedure to handle the clicked event of the Close button (The [X] button on the top right coner of a VB form. I want to be able to query the users intention for clicking, like: Does he want to save before closing ... instead of just closing the window.

I used a command button to achieve this but I also want to do same for the Close button.
Please, DO NOT post questions in the Member Introductions Forum. Heck, there is even a thread with a title asking you not to.

I am moving this question to the VB forum.

Regards,

Jeff
Nov 29 '07 #2

Mohan Krishna
100+
P: 115
Hi everyone,
Can someone help me with a procedure to handle the clicked event of the Close button (The [X] button on the top right coner of a VB form. I want to be able to query the users intention for clicking, like: Does he want to save before closing ... instead of just closing the window.

I used a command button to achieve this but I also want to do same for the Close button.
Hi
Try...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Terminate()
  2.     MsgBox "Hai"
  3. End Sub
  4.  
ALL THE BEST!
respond is it helpful...
Nov 29 '07 #3

Expert 5K+
P: 8,434
The details will depend on what version of VB you're using.

In VB6 you would use the form's QueryUnload and/or Unload events.
Nov 29 '07 #4

lotus18
100+
P: 866
The details will depend on what version of VB you're using.

In VB6 you would use the form's QueryUnload and/or Unload events.
But it depends on the form and/or type of application. Let us say for an instance we have 1 form and containing all the list of any record, then when adding/modifying a particular record we're using another form and it is shown as vbmodal. What if the user add new record, how can you unload that form without prompting a message box? : )

Rey Sean
Nov 30 '07 #5

Expert 5K+
P: 8,434
But it depends on the form and type of application. Let us say for an instance we have 1 form and containing all the list of any record, then when adding/modifying a particular record we're using another form and it is shown as vbmodal. What if the user add new record, how can you unload that form without prompting a message box? : )
Seems to me, that's way off-topic for this thread. We're dealing with kind of the oposite - what to do when the user clicks Close.

You probably should start a new discussion for your question, including as much detail as possible about the situation.
Nov 30 '07 #6

lotus18
100+
P: 866
Hi Killer42

I was only just gave my opinion and it was relevant to the topic. I'll post that question soon : )

Rey Sean
Nov 30 '07 #7

Mohan Krishna
100+
P: 115
Hi Killer and Lotus,

Very good discussion!
Here we can use any of the above Form Events.
But as Lotus raised a question, it makes some problem when another form is shown MODAL. Please Lotus post a new thread and we try to get a solution.

But where is Kabyr whether he got the solution from this good discussion.
Thank you both of you!

This is my 100th post.

Thank You ALL!
Nov 30 '07 #8

lotus18
100+
P: 866
Hi Killer and Lotus,

Very good discussion!
Here we can use any of the above Form Events.
But as Lotus raised a question, it makes some problem when another form is shown MODAL. Please Lotus post a new thread and we try to get a solution.

But where is Kabyr whether he got the solution from this good discussion.
Thank you both of you!

This is my 100th post.

Thank You ALL!
Hi Mohan

Congrats for your 100th post. haha...

I think Kabyr got the solution from this forum. OK, I'll post the question later, I have some work out here. lol : )

Rey Sean
Nov 30 '07 #9

9815402440
100+
P: 180
hi

use following code

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("do you want to close this form", vbYesNo) = vbNo Then
Cancel = 1
End If
End Sub

regards
manpreet singh dhillon hoshiarpur
Nov 30 '07 #10

Mohan Krishna
100+
P: 115
Hi Mohan

Congrats for your 100th post. haha...

...lol : )

Rey Sean
Thank You Lotus!
This is a very good and quick responsive forum!
Nov 30 '07 #11

lotus18
100+
P: 866
Thank You Lotus!
This is a very good and quick responsive forum!
Hello Mohan

I've just posted the question as you requested : )
As you've said, this will gonna be interesting lol (haha)

Rey Sean
Nov 30 '07 #12

Kabyr
P: 29
Thanks everyone!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Form_Unload did the job.

You made my day.
Dec 1 '07 #13

Expert 5K+
P: 8,434
Glad we could help. :)
Dec 13 '07 #14

Post your reply

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