Cancel Form Close

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. I'm wondering if there' a way to cancel the form close event. I want
to perform some validation after a user clicks the 'X' at the top right, but
I need to be able to cancel the event in certain circumstances.

Is it possible to do this?
 
in message:
Hello. I'm wondering if there' a way to cancel the form close event. I want
to perform some validation after a user clicks the 'X' at the top right, but
I need to be able to cancel the event in certain circumstances.

Is it possible to do this?

Use the form's Unload event for this since it has a Cancel argument.
A simple example for illustration:

Private Sub Form_Unload(Cancel As Integer)
If Me.chkMyCheck = True Then
' Ok to close
Else
MsgBox "Cannot Close"
Cancel = True
End If
End Sub
 
Dan Jeff is correct that you can cancel the closing of a form in its Unload
event.

However, if you want to validate the entry and prevent it from being saved
if the entries are unacceptable, you need to use Form_BeforeUpdate. The
record is already saved by the time Form_Unload occurs.
 
Good point Allen, I should have addressed that.

--
Jeff Conrad
Access Junkie
Bend, Oregon

"Allen Browne"wrote in message
Dan Jeff is correct that you can cancel the closing of a form in its Unload
event.

However, if you want to validate the entry and prevent it from being saved
if the entries are unacceptable, you need to use Form_BeforeUpdate. The
record is already saved by the time Form_Unload occurs.
 
Back
Top