473,503 Members | 6,385 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 1826
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
4596
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...
0
1012
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
1711
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
3919
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">....
2
2921
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...
4
9517
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...
6
3915
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...
1
1349
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...
3
1730
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...
5
4071
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
7070
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
7316
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...
0
5566
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,...
0
4666
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...
0
3160
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.