Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ensuring validation before closing a form

Status
Not open for further replies.

charle525

MIS
Jul 18, 2003
23
0
0
US
On my form, I am validating and giving the option to save a record before closing. I coded a button to do this and disabled the 'x' close button, but how do I prevent the user from closing on the 'File' menu or using Ctrl-F4? I tried using the 'Close' event to perform validation but that's no good because I want the user to have the option of canceling the Close. Can I prevent these other ways of closing the form, or can I programmatically cancel the Close event after using these other close methods? Thanks.
 
use the Form's BeforeUpdate Event

If Me.Dirty Then
If MsgBox("Changes Made, Do You Wish to Save them?", vbYesNo, "Changes Not Saved") = vbNo Then
DoCmd.CancelEvent
Exit Sub
End If
End If
 
I should have mentioned this before. That code works well and I've used something similar before, but many of my forms have subforms, and each time a user clicks on a subform, they would get prompted to save or not. It would get annoying to be prompted everytime they click on or off a subform. Any suggestions on avoiding this? (Also, I'm trying to stick with using bound forms if possible) Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top