469,575 Members | 1,365 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

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 4620
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Tyce | last post: by
4 posts views Thread by Gabriella | last post: by
5 posts views Thread by jimmy | last post: by
3 posts views Thread by =?Utf-8?B?QVRU?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.