473,471 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Create 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 4800
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.googlegr oups.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.googlegr oups.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
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...
4
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...
3
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...
5
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...
3
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...
13
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...
1
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...
0
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...
5
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...
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
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,...
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
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...
1
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...
1
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.