473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I prevent a form's being closed based on some of the control values?

sueb
379 256MB
I have a form that has several checkbox controls on it. When the user tries to close the form (his options for closing the form are not constrained in any way), I want to evaluate those checkboxes, and prevent the close if all are False (unchecked).

Would this go in the form's On Unload event? The On Close event? I don't have a clear understanding of the difference between when these events happen, but, because of their arrangement in the Properties window, I'm assuming that On Unload happens first. What triggers it? Is that where I get a chance to stop the On Close event?

And in either case, what command do I use in the code? I'll want to put up a message box that tells the user what the problem is and returns him to the form to correct it.

Thanks!
May 19 '11 #1
2 2135
TheSmileyCoder
2,322 Expert Mod 2GB
If in doubt about the order of events in access, the easiest approach is to simply write a msgbox code in each event. In the form_Load you just write for example:
Expand|Select|Wrap|Line Numbers
  1. Msgbox "Form Loading"
Also if you look at the 2 events, by clicking the builder (the ... on the right of the event property) you will see:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel as Integer)
  2. Private Sub Form_Close()
From here you can see that the unload event can be cancelled while the close event can not. The unload event happens first.
May 19 '11 #2
NeoPa
32,556 Expert Mod 16PB
Within the Form_Unload() event, if you want to cancel the close, simply set the parameter Cancel to True. If, when the event procedure completes, this parameter is found to be True, the close will cancel. Clearly, it delaults to False and only by setting it explicitly will it cancel the further processing of the event.

PS. The Help system also gives a clear indication of which order the events are fired in.
May 19 '11 #3

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

Similar topics

3
by: babu | last post by:
Hello All, How are you? I am facing an issue to print all the form control values (including datagrid values). Is there a way to print all the control values in VB.NET. If the grid...
1
by: Chris John Jordan | last post by:
Can anyone suggest a way of getting FORM to post only its own control values? I find by default each FORM on a page POSTs the variables of all FORMs on the page, and this prevents my common ACTION...
1
by: Cezar | last post by:
I am new to Web Forms and I ported my little app from Windows Forms to ASP.NET and I am wondering why some things are not working as before. Although I figured most of them, one of them is that on...
0
by: Materialised | last post by:
Hi All I have been searching the net on this for the last couple of hours to no avail. I need to fill a datagridview control based on the values entered in 2 text boxes. However I cant for...
6
by: Materialised | last post by:
Hi All I have been searching the net on this for the last couple of hours to no avail. I need to fill a datagridview control based on the values entered in 2 text boxes. However I cant for...
5
by: Lewis Perin | last post by:
Is anyone aware of robust software, suited to a preexisting PHP application, that handles permissions for various types of requests by role rather than user ID? I'm speaking of maintaining/editing...
7
convexcube
by: convexcube | last post by:
To keep a record of training levels for different tasks, I have 18 option groups with 4 options values each: 0 labelled as "None", 1 labelled as "Trainee", 2 labelled as "Competent" and 3 labelled as...
8
by: xz | last post by:
Why C++ (as well as Java) adopts class-based access control instead of instance-based access control? I had never paid attention to whether an access-control is class-based or instance-based but...
3
by: nassim.bouayad.agha | last post by:
Hello, I am seeking for information about conditional XSD validation based on elements values,but unfortunatly,I could not find a clear answer.Let's say that I have three XML elements named...
1
by: avecreep | last post by:
Hi, i was trying to find a web application and i found one open source on the internet. i put the code folders on the root folder and when i tried to acces via web browser it all worked fine ( i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.