473,651 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot close form unless Save button is clicked

Hi,

I have a form that requires a save button to be clicked before closing
the form. I would like a msgbox to pop up when the button is not
clicked before closing. Can someone show me how i would code this?
Thanks!

Aug 13 '07 #1
2 4813
I believe the following will do what you're asking:

Step 1 - Open the Form's code module and at the very top, just before the
first Sub or Function enter
'This is a Global variable, available to all of the procedures in this
module

Dim OKtoClose as Boolean

Step 2 - Go to the Form's Event Property tab and create an OnDirty event
procedure that sets OKtoClose to False. This event fires as soon as anyone
makes any change that would require a save.

OKtoClose = False

Step 3 - Go to the Form's Event Property tab and create an OnUnload event
procedure that Checks the status of OKtoClose and Cancels the Unload
(Close) if OKtoClose is not True.

If Not OKtoClose then
msgbox "You Need To Press the Save Button Before You Can Close This
Form"
Cancel = True
End if

Step 4 - Go to your Save Button's OnClick event procedure and (after the
DoCmd line) set OKtoClose to True

OKtoClose = True

Warning, as you may know, Access automatically saves as you move from record
to record. This procedure will force the user to press the save button
before they can close the form even if the record may not need saving.

Len Robichaud
"Eric" <er************ @gmail.comwrote in message
news:11******** **************@ b79g2000hse.goo glegroups.com.. .
Hi,

I have a form that requires a save button to be clicked before closing
the form. I would like a msgbox to pop up when the button is not
clicked before closing. Can someone show me how i would code this?
Thanks!
Aug 13 '07 #2
On Aug 13, 10:48 am, "Len Robichaud" <len.robich...@ rqwproserv.com>
wrote:
I believe the following will do what you're asking:

Step 1 - Open the Form's code module and at the very top, just before the
first Sub or Function enter
'This is a Global variable, available to all of the procedures in this
module

Dim OKtoClose as Boolean

Step 2 - Go to the Form's Event Property tab and create an OnDirty event
procedure that sets OKtoClose to False. This event fires as soon as anyone
makes any change that would require a save.

OKtoClose = False

Step 3 - Go to the Form's Event Property tab and create an OnUnload event
procedure that Checks the status of OKtoClose and Cancels the Unload
(Close) if OKtoClose is not True.

If Not OKtoClose then
msgbox "You Need To Press the Save Button Before You Can Close This
Form"
Cancel = True
End if

Step 4 - Go to your Save Button's OnClick event procedure and (after the
DoCmd line) set OKtoClose to True

OKtoClose = True

Warning, as you may know, Access automatically saves as you move from record
to record. This procedure will force the user to press the save button
before they can close the form even if the record may not need saving.

Len Robichaud

"Eric" <eric.nguyen... @gmail.comwrote in message

news:11******** **************@ b79g2000hse.goo glegroups.com.. .
Hi,

I have a form that requires a save button to be clicked before closing
the form. I would like a msgbox to pop up when the button is not
clicked before closing. Can someone show me how i would code this?
Thanks!
Thanks Len! That worked!

Aug 13 '07 #3

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

Similar topics

2
12877
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the ComboBox. I get no errors or problems, it just will not work. At load time I am retrieving dates from an Oracle database and adding them to the ComboBox with out any problems. However, once the application is up and running I cannot add to the...
4
21275
by: Gabriella | last post by:
Hi, I have a popup window that opens from a page on my website. This popup is a form with several fields. Upon submit button it redirects to a server side ASP page which writes all data to the DB. I would like the popup to close immediately after the submit button is clicked, and data is saved, (or cancel button) - but this does not happen.
3
10565
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The other one is Next button which i created to open another form "frmSummary" which displays back the records submitted. (i used the wizard to open form and find specific records to display. All these works superb until a review by users where they...
5
34359
by: jimmy | last post by:
Hi all, I want to capture the event when the browser's close button is clicked in an html page. I tried using the event.ClientX and event.ClientY property in the body unload event, and this helps to recognise whether the close button is clicked( also differentiates whethet refresh was clicked). The problem arises whenever i try to close the window by resizing it or by right clicking at the bottom of the page and then closing it. Can...
3
2533
by: =?Utf-8?B?QVRU?= | last post by:
When user click on the "x" close button on the MDI parent form, how can I set an event handler on it? I want to save some settings before the form is closed. Some forum mentions associate it with the cancel button, there is no button here. Anthony.
13
11347
Kabyr
by: Kabyr | last post by:
Hi everyone, Can someone help me with a procedure to handle the clicked event of the Close button (The button on the top right coner of a VB form. I want to be able to query the users intention for clicking, like: Does he want to save before closing ... instead of just closing the window. I used a command button to achieve this but I also want to do same for the Close button.
1
6107
by: QCLee | last post by:
Hello Sir, Im here again asking for help. I have a form and a subform relate to HVAC Windward Table. i have a SAVE button on the form that when clicked it saves data on the HVAC Windward Table but not in a subform. When manually inputing data into subform it saves by work order on the HVAC Windward Table in subdatasheet even if how many times i add data in one work order. Sir, Is it posible that when i clicked on the SAVE button in the form it...
0
2373
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and handle the situations after the Access Close button has been clicked. I have been largely...
5
5877
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and handle the situations after the Access Close button has been clicked. I have been largely...
0
8349
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...
1
8460
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
7296
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
6157
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
5609
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
4143
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
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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
1585
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.