473,699 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Put If e.Cancel Then Exit Sub in Closing event

Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another when
its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled to
true will e.cancel be true when the next form receives a closing event?

Does your answer also apply the MdiChildren?

Thanks


Nov 7 '06 #1
4 3002
" Academic" <ac************ @a-znet.comwrote in message
news:OH******** ******@TK2MSFTN GP03.phx.gbl...
Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another when
its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled to
true will e.cancel be true when the next form receives a closing event?

Does your answer also apply the MdiChildren?
If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
>
Thanks


Nov 8 '06 #2
Michael C wrote:
" Academic" <ac************ @a-znet.comwrote in message
news:OH******** ******@TK2MSFTN GP03.phx.gbl...
I guess what I'm asking is will that work. If one form sets e.cancelled to
true will e.cancel be true when the next form receives a closing event?

If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
Just wondering, will the forms always receive the event in a
predictable order?

Nov 8 '06 #3
I hate to generalize from a test so I won't. But in my situation a test
shows that if I have a MdiContainer open and a bunch of standard forms also
open and a bunch of MdiChildren also open, the all the standard forms
receive the Closing event even if one cancels. I'm closing the forms one at
a time in the MdiContainer Closing routine so maybe that makes a difference.

Also, e.Cancel is always false on entering except for MdiChildren where
e.Cancel remains true once a closing event sets it to True.

Not very neat.

Also, in this test, the forms received the event in the order they were
open - made no difference which had focus or which was topmost

"Michael C" <no****@nospam. comwrote in message
news:uM******** ******@TK2MSFTN GP03.phx.gbl...
>" Academic" <ac************ @a-znet.comwrote in message
news:OH******* *******@TK2MSFT NGP03.phx.gbl.. .
>Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another when
its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled
to true will e.cancel be true when the next form receives a closing
event?

Does your answer also apply the MdiChildren?

If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
>>
Thanks



Nov 8 '06 #4
I found this on the Internet. Agrees with my test except for the
MdiChildren value of e.cancel. Also, I can't think of a situation where if a
user canceled the app shutdown you would want to run all the other form
events but I suppose it could happen.

guess it's time to move on.

Thanks again

The event is broadcast by the multi-cast delegate just like any other
event. This delegate has no knowledge of the Cancel property or what
it is for. It always sends the event to all subscribed delegates.
Also, there are situations where you have multiple listeners of the
closing event and you want them to all fire off even if one of them
says to cancel.
If what you're doing doesn't need to run if something else cancelled,
then it's good practice to add this check at top of routine.


" Academic" <ac************ @a-znet.comwrote in message
news:Ol******** ******@TK2MSFTN GP02.phx.gbl...
>I hate to generalize from a test so I won't. But in my situation a test
shows that if I have a MdiContainer open and a bunch of standard forms also
open and a bunch of MdiChildren also open, the all the standard forms
receive the Closing event even if one cancels. I'm closing the forms one
at a time in the MdiContainer Closing routine so maybe that makes a
difference.

Also, e.Cancel is always false on entering except for MdiChildren where
e.Cancel remains true once a closing event sets it to True.

Not very neat.

Also, in this test, the forms received the event in the order they were
open - made no difference which had focus or which was topmost

"Michael C" <no****@nospam. comwrote in message
news:uM******** ******@TK2MSFTN GP03.phx.gbl...
>>" Academic" <ac************ @a-znet.comwrote in message
news:OH****** ********@TK2MSF TNGP03.phx.gbl. ..
>>Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another
when its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled
to true will e.cancel be true when the next form receives a closing
event?

Does your answer also apply the MdiChildren?

If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
>>>
Thanks




Nov 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2517
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window catches its Closing event and cancels it if the user wants to save the data, but when the Application closes this event isn't thrown automatically. I added a loop to close each child window, but can't seem find how to catch the child window's cancel of the Closing event, so even if the user...
4
1826
by: Deano | last post by:
Alot of my forms are bound. I would like to offer a Cancel option so that they can make as many changes as they like and still Cancel out without making any changes. I have one idea of how to do this for new records; tag each record with a boolean value. On clicking OK, these are all set to True and the form closes. If they Cancel the False records are deleted and the form closes.
6
8574
by: Carl | last post by:
Hi you al I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goe ' Calls this method from the InitializeComponent() method of your form Private Sub OtherInitialize( AddHandler Me.Closing, AddressOf Me.Form1_Cance End Sub 'OtherInitializ Protected Sub Form1_Cancel(sender As Object, e As CancelEventArgs If Not myDataIsSaved The
3
2771
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set the value to False, but I would have expected it to be False on entry. TIA Charles
2
1542
by: Just Me | last post by:
I've seen this in example code: Private Sub Studio_Closing(ByVal sender A..snip.. Handles MyBase.Closing If e.Cancel Then Exit Sub ....snip... It would make sense if Windows keeps doing Closing events even after it receives an e.Cancel=true.
3
6368
by: Oenone | last post by:
I'm writing an application with various MDI child forms. In the Closing event of many of the forms, I have code that asks the user whether he is sure he wants to close the form, because it contains unsaved data. If the user clicks "No" then the code sets e.Cancel = True, which cancels the closure. This works just great. But when the user closes the MDI parent form, the cancellation seems to be completely ignored. The MessageBox...
2
3290
by: Bob | last post by:
In a winform with a datagridview using cellvalidating event but also have a save button that is located on a tablebindignnavigator. The behaviour I observe is that if the cellvalidating issues a cancel = true after the save button has been clicked, the update statements in the click event of the save button still occur but nothing gets saved, which is OK. Except that I pop a message box in the click event after the update statements have...
21
9178
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
6
7725
by: MLH | last post by:
I have a form, frmUSPSReturnReceipts, with a control named NotExpectingGreenTickets. The control's Exit event procedure follows: Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer) If IsNull(Me!NotExpectingGreenTickets) Then DoCmd.CancelEvent Exit Sub End If End Sub
0
8706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8631
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8945
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7787
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4392
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4641
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.