473,545 Members | 2,135 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 4809
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
12869
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...
4
21266
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...
3
10553
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...
5
34353
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...
3
2531
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
11307
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...
1
6099
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...
0
2370
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...
5
5868
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...
0
7468
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...
0
7401
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...
0
7656
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. ...
1
7423
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...
0
7757
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5329
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...
0
4945
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...
0
3450
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...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.