Stop a OnClose event of a form

N

Neil

I have a form which checks whether a field has been inputted before closing.
I have a message box that works ok with the check but i have the evnt on the
ONCLOSE of the form
With this in mind, if the field in question hits the check and fails i want
to cancel the onclose of the form, how can this be done please?

Or can this be done any other way?

Thanks,

Neil
 
R

Rick Brandt

Neil said:
I have a form which checks whether a field has been inputted before
closing. I have a message box that works ok with the check but i have
the evnt on the ONCLOSE of the form
With this in mind, if the field in question hits the check and fails
i want to cancel the onclose of the form, how can this be done please?

Or can this be done any other way?

You cannot cancel the Close event, but you can cancel the Unload event. Move
your code there and add the line...

Cancel = True

....when the check fails.
 
R

Rick Brandt

Neil said:
no still doesn 't work. the form still closes even with the fail.

Post your code. I just tested the following...

If OkToClose = False Then
Cancel = True
End If

....in the Unload event of a form. OkToClose being a Yes/No field on the form.
When the control is false the form does not close.
 
N

Neil

If Priority = "0" Then
MsgBox "Priority must be set", vbOKOnly, "Priority Missing"
Cancel = True
Else
Cancel = False
End if

Where Priority is my field that changes with a selection (of 1 to 3) in the
form


Thanks.
 
R

Rick Brandt

Neil said:
If Priority = "0" Then
MsgBox "Priority must be set", vbOKOnly, "Priority Missing"
Cancel = True
Else
Cancel = False
End if

Where Priority is my field that changes with a selection (of 1 to 3)
in the form

Do you get the message box? Also you don't need to set Cancel = false in the
Else block. It is already False unless set to True.
 
Top