By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,841 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,841 IT Pros & Developers. It's quick & easy.

Cannot close form unless Save button is clicked

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.