469,353 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

QueryUnload

Hi Huys,

When the "X" is pressed, I know that QueryUnload is called.

I want to be able to put up a box, asking the user if they are sure.. If
yes then
the programme will end. If the answer is no, how do I prevent the form from
unloading?

TIA.

Steve.
Jul 17 '05 #1
7 9966
"Steve" <al************@twat.com> wrote
When the "X" is pressed, I know that QueryUnload is called.

I want to be able to put up a box, asking the user if they are sure.. If
yes then
the programme will end. If the answer is no, how do I prevent the form from
unloading?

Did you try changing Cancel to True? Highlight QueryUnload in
the VB code window and press F1 for help on that event....

LFS



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #2

cancel = msgbox ( "want to quit", vbquestion or vbYesNoCancel, "Eh?") =
vbYes

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.

There' no place like 127.0.0.1
"Steve" <al************@twat.com> wrote in message
news:rh********************@karoo.co.uk...
: Hi Huys,
:
: When the "X" is pressed, I know that QueryUnload is called.
:
: I want to be able to put up a box, asking the user if they are sure.. If
: yes then
: the programme will end. If the answer is no, how do I prevent the form
from
: unloading?
:
: TIA.
:
: Steve.
:
:
Jul 17 '05 #3
Set the 1st parameter to True to prevent the form from unloading.
"Steve" <al************@twat.com> wrote in message news:<rh********************@karoo.co.uk>...
Hi Huys,

When the "X" is pressed, I know that QueryUnload is called.

I want to be able to put up a box, asking the user if they are sure.. If
yes then
the programme will end. If the answer is no, how do I prevent the form from
unloading?

TIA.

Steve.

Jul 17 '05 #4
> When the "X" is pressed, I know that QueryUnload is called.

I want to be able to put up a box, asking the user if they are sure.. If
yes then
the programme will end. If the answer is no, how do I prevent the form from
unloading?

Use this event to show your Msgbox. The variable Cancel contains whether the
form continues or not.
Basically,

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("Are you sure?", vbYesNo, "Quit") = vbNo Then Cancel = 1
End Sub

does a good job.

--
QuickHare
QuickHare @ Hotmail. com


Jul 17 '05 #5

"QuickHare" <Qu*******@Hotmail.c> wrote in message
news:bu*************@athena.ex.ac.uk...
When the "X" is pressed, I know that QueryUnload is called.

I want to be able to put up a box, asking the user if they are sure.. If yes then
the programme will end. If the answer is no, how do I prevent the form from unloading? Use this event to show your Msgbox. The variable Cancel contains whether

the form continues or not.
Basically,

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("Are you sure?", vbYesNo, "Quit") = vbNo Then Cancel = 1
End Sub

does a good job.

--
QuickHare
QuickHare @ Hotmail. com


Thankyou for all you reply's.

Steve!
Jul 17 '05 #6
If MsgBox("Are you sure?", vbYesNo, "Quit") = vbNo then the result of the
Msgbox call is True.

If MsgBox("Are you sure?", vbYesNo, "Quit") = vbYes then the result of the
Msgbox call is also True.

If Cancel is set to True, the unload is aborted. Therefore,

Cancel = MsgBox("Are you sure?", vbYesNo, "Quit") = vbNo

or, if you want a more positive approach ...

Cancel = MsgBox("Are you sure?", vbYesNo, "Quit") = vbYes

does it without the If.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.

There's no place like 127.0.0.1

Jul 17 '05 #7
> If MsgBox("Are you sure?", vbYesNo, "Quit") = vbNo then the result of the
Msgbox call is True. Only if the user selects No (why would the user want it closed if their not sure
to close it?).
If MsgBox("Are you sure?", vbYesNo, "Quit") = vbYes then the result of the
Msgbox call is also True. Only if the user selects Yes.
does it without the If.

Fair enough. I just threw it in for ease of understanding. Those wanting to know
more about MsgBox results would hopefully look it up in help!

--
QuickHare
QuickHare @ Hotmail. com
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Wortelvisje | last post: by
2 posts views Thread by Kevin Robinson | last post: by
5 posts views Thread by Mike Labosh | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.