Prevent Form Close

BLD

New member
Local time
Today, 00:45
Joined
Jun 26, 2015
Messages
6
I am using access 2007 and I am trying to get the code below to verify if 2 fields on the form are blank before closing. I tried using this in the close event and unload event and it does not work, just closes regardless of the fields.


If [field1] = "" and [field2] = "" then

Msgbox " You must enter a value in either field 1 or field 2"
Cancel = false

Else

Cancel = true

End If

Thanks for any assistance!
 
you want the forms before_update event, but if someone presses the close button, the form will still close with the message something like "unable to save the record at this time"

I do not think it is possible to cancel the close button click, and retain the data, with normal event handlers. (although maybe you can do it with lowlevel keypress stuff)
 
Thanks, it will work in the before_update event but it does not prevent the user from disregarding the message and closing the form and saving the record.
 
as I say, I don't think it is possible.

in addition to what I suggested before - you can also remove the close button, and add you own - and then you will be able to manage the form closing.
 

Users who are viewing this thread

Back
Top Bottom