473,396 Members | 2,029 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.

Block x in Form Closure

{This question was moved from the article How to Close a Main Form Without Saving Changes of any Subforms}

What about when the user clicks the red "X" button to close the form? Is there any way to automatically discard these changes to the form/subform design? Or do I just have to set turn off the "close button" and force the user to use my custom "close" button?
Jun 11 '14 #1
9 1342
twinnyfo
3,653 Expert Mod 2GB
PJ,

I would think that you could call this sub from the OnClose Event of your Form (which is irrespective of any Close Command Buttons).

When I build Forms, I have a tendency to have a set series of actions that are performed in the OnClose event of the Form (i.e. call up the Switchboard), but when I click the Close Button, there may be some other things the Form wants to do befor it actually closes (like saving certain bits of information or downloading reports).

Although I haven't had too many problems of Access redesigning my SubForms, at least now, if I notice any such activity, I will have a way to address it.

Thanks for your insights, NeoPa!
Jun 11 '14 #2
NeoPa
32,556 Expert Mod 16PB
Hi PJ.

Twinny has pretty-well answered as I would have. The Form_Close() event procedure is triggered by both clicking on the red "X" and when DoCmd.Close() is used. Another possible event procedure that could be used is Form_Unload().
Jun 22 '14 #3
Access asks to save any changes to form design before any of the form events (including Form_Close) are triggered. So code there is too late. In particular, when a subform is displayed as a datasheet, the user can show/hide columns, rearrange columns, etc. These are all design changes that Access wants to save. I want to avoid that prompt from Access
Jun 24 '14 #4
twinnyfo
3,653 Expert Mod 2GB
If you don't want that prompt to pop up to save the form design (which is induced by any changes made in datasheet view), then, when the form closes, turn off the prompt to save:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acForm, Me.Form.Name, acSaveNo
That should help in this case.....
Jun 24 '14 #5
When the user clicks the red X, Access prompts for saving design changes BEFORE the Form_Close event.
Jun 24 '14 #6
twinnyfo
3,653 Expert Mod 2GB
PJ,

Another reason I always disable that pesky little button. I always recommend that the VBA should control everything that goes on in the form. It may be possible to trap this event, but since I don't build my forms this way, I admit, it is unknown to me.
Jun 24 '14 #7
Thanks. I was just hoping there was a way through Windows API to intercept the click on the red X. I have disabled it on the form with the datasheet subform but wanted some way to have it for consistency with all the other forms.
Jun 24 '14 #8
NeoPa
32,556 Expert Mod 16PB
In my previous post (#3) I mention both the Form_Unload() and the Form_Close() event procedures. The major difference between the two is that the Unload event can be canceled, but the Close event can't.

To ensure that no design changes are saved automatically when the form is closed have a Command Button on your form that handles closing. In there call for the close with code similar to :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.Close(ObjectType:=acForm, _
  2.                  ObjectName:=Me.Name, _
  3.                  Save:=acSaveNo)
It's also important to flag that the close has been called from your trusted routine rather than any other method (Red "X"; Ctrl-F4; etc.) so define a Boolean variable that is Private to the Form module which is typically unset (False). In this routine add a line to set it to True.

In Form_Unload() check this variable and set the Cancel parameter to Not this variable. This will ensure that when any other method of closure is attempted the Unload will cancel and the Close won't proceed. Only your procedure will allow for the form to close, and it will ensure changes are never saved.

How to Close a Main Form Without Saving Changes of any Subforms has information on how to ensure nothing is upset when dealing with subforms.
Jun 24 '14 #9
NeoPa
32,556 Expert Mod 16PB
I've just reread post #1 to be reminded that your question originally started from the thread I just relinked you to. As the answer to everything you've asked is already encapsulated within that thread I must conclude that your difficulty is in interpreting what is in there rather than finding the information. Feel free to explain what it is that's confusing you and I'm sure we can help you understand it better.
Jun 24 '14 #10

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

Similar topics

8
by: DFN-CIS NetNews Service | last post by:
I don't seem to see the following structure very often ... <root> <e1>this <e2/> <e3>that</e3> </e1> </root> That is an element with text /and/ child nodes.
1
by: axxegfx | last post by:
I'd like, how can i do this with a thread app?? 1- Don't block form o graphic interface app 2- into thread and into a for-next located into the thread ,print a local for-next var i think i...
2
by: Byron | last post by:
I'm new to C# and threading, so hopefully this is a simple newbie question. I have a form that is supposed to listen for network traffic on a given port and decode and display any interesting...
1
by: Jules Winfield | last post by:
My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this:...
1
by: Chris Tillotson | last post by:
Thanks in advance... I have an odd problem. I developed a .net app on my home computer and it works fine but when I put it on the hosted environment my ImageButtons that are supposed to post my...
6
by: peek | last post by:
This has probably be asked before but I'm trying to trap the event before a user closes the main form of VB.NET application to show an error message if there are unsaved changes. Can anyone point...
1
by: Deano | last post by:
I'm having this problem when closing a form that I really don't think should be happening; This is the last section of code in the afterupdate of a combo box in form frm_Agency; ...
0
by: Deano | last post by:
I'm having this problem when closing a form that I really don't think should be happening; This is the last section of code in the afterupdate of a combo box in form frm_Agency; ...
2
by: blobb | last post by:
hi all, take a look to the file. http://www.vkuskofe.com/pics/ff_ie.gif this is form in table, located in DIV layer. on the left is FF and on the right is IE. as You see, FF displays it...
9
by: NitinSawant | last post by:
I have following HTML page created using javascript jquery, This doesn't work when I click on continue button, help <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.