473,657 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to prevent saving data on form in access 2003 when user clicks close button?

23 New Member
Hi.
Can any one tell me----
how to prevent saving data on form in access 2002 or 2003 when user clicks close button of the window or during abnormal shutdown ?
Dec 22 '13 #1
2 1833
Narender Sagar
189 New Member
Select any important field of the table (on which form is linked) and set 'Required' property to 'Yes'.
Access will not save record until value in that field is entered.
Hope this will serve your purpose.
Dec 22 '13 #2
zmbd
5,501 Recognized Expert Moderator Expert
@Narender: It's not that simplistic. If you will read the OP this is about both the close AND abnormal shutdowns, worse, OP has failed to tell us anything about the design of the form.

@MoonRB: You need to provide much more detail about the form design, if you are concerned about new records, editing existing records, or both.

Narender Sagar does have a point with the required field, however, this is not fool proof and in the correct situations can still have some goofyness happen.

Depending on the form design the edits may or may not have happended, only bound forms and controls have the me.dirty property available so to provide more information here will take a little more detail; however, in general it will involve the before update event of the form and setting cancel to true and hopfully the me.undo is available.

Abnormal shutdowns are very difficult to deal with and you will need to describe what is happening.

To prevent your form from closing by using either the form close button and/or usually the program:

In the declarations section of the form place a private boolean z_blnAllowClose

In in on load event of the form set the private boolean z_blnAllowClose to false

In the on click event of your close command button set the boolean z_blnAllowClose to true

In the unload event of the form, if the boolean z_blnAllowClose is true then set cancel to false (default) if the boolean z_blnAllowClose is false then set the cancel to true, I use the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.     Cancel = Not z_blnAllowClose
  3. End Sub
It's a little counter intuitive. Cancel = true means to stop the unload event from happening.

In the before update event I would check the z_blnAllowClose boolean for a true state and set the cancel for the event to true and attempt the me.undo which will stop most dirty record saves. Be careful with the code here in that you don't want to interfere with validation code etc...

Attempt this and let us know what happens, show us the work you've done so that we can help you tweek the code.
Dec 23 '13 #3

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

Similar topics

5
4607
by: Bruce | last post by:
I have a number of forms that do significant work based on variables POSTed from the form. What is the common method of detecting and preventing this work from being done when the form is POSTed as the result of the user clicking the Back or Reload buttons in the browser? --Bruce
0
1023
by: ajay | last post by:
How can i prevent a model form from closing on click of ok button which is of model type using C# in windows form.
2
1740
by: Asit | last post by:
How can i know when user clicks X button of the browser ? I have to write some code when user clicks X button of browser. What is the event for capturing this event ? Help needed ASAP. Asit
1
3936
by: Bucky | last post by:
I haven't found any vbscript code that can stop the form submission/postback after the msgbox. The problem is that asp:button is rendered as <input type="submit"> instead of <input type="button">. So instead of doing a "document.form(0).submit" upon "Yes", I need to stop the form submission upon "No". Javascript is easy since you can do "return confirm...", but I'm looking for a vbscript solution. Here's my relevant code: <asp:button...
2
2933
by: jburkle | last post by:
The following is the onclick method called when the "Renew" button is clicked by the user in my Windows application: ..... Private Sub cmdRenew_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRenew.Click Try If x Is Nothing Then
4
9523
by: morc | last post by:
hi, is there any way to refresh the page when the user clicks back button?I have a jsp page that i need to regerenate everything everytime the user visits it. its either that or i want to disable the back button so to force the user to click a link so that hte page is refreshed. If anyone knows how to refresh on back button click or disable the back button please help me out.
6
3934
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a signal to server. This seems to be achievable with body unload events, but it is little too much, as even if user navigate within my site, this event will be generated, this can be avoided by handling onclick of each link, so that I'll know exactly...
1
1358
by: sowen | last post by:
I am using the ExtensibleDialog to create a dialog for our internal program use. We want the user select some items in our own controls, and then generate the filename to the textbox. But that is just the temporary filename, the final filename can only be generated after the user clicks "OK" button, because of some concurrency issues. I can use OFNHookProc to catch the event when the user clicks OK button, and get the filename from...
3
1744
by: gimme_this_gimme_that | last post by:
Depending upon a radio button button's setting a div is either hidden or visible. It turns out that the default view of the page requires that the div be hidden. When the user opts for the setting that makes the div visible, clicks, and then clicks the back button the page renders with the div hidden. I've tried a few strategies to handle this. Adding no-cache meta tags
5
4078
by: giandeo | last post by:
Hello experts. Could any one suggest me how I could convert an asp page into pdf (on-the-fly) when a user clicks a button on a web page. Waiting impatiently for your reply. Giandeo
0
8303
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
8821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8502
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
7316
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
6162
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
5632
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.