Cancel Close Button

  • Thread starter Thread starter Michael R
  • Start date Start date
M

Michael R

I am creating a number of Forms to be used as my UI. One
of the requests from the Management was that I use the
standard Close button on the Forms to exit them. I also
need to use a 'Are you sure?' dialog box to make sure
that they really wanted to close the Form. Is there any
way to Cancel the Close action once the Close Button is
clicked?

I tried a CancelEvent with a Dialog asking the Yes/No
question in onClose, but it closes no matter whether they
answer Yes or No.

Any ideas?
 
In the unload event of the form, add some code, eg:

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Close, Really. Are you sure?", _
vbYesNo) = vbNo Then Cancel = True
End Sub
 
Mike,

The code here will work but you need the following code for your Close button:

On Error Resume Next
DoCmd.Close

Without the error handling, you will get an error message if you cancel the
unload in Ruskin's code.
 
Back
Top