Cancel a close command

T

TESA0_4

Hi,
If the intrinsic close command button at the top right of a form is clicked
when a record is incomplete, the usual Access error messages are displayed.
How can I detect that the user has clicked the form close button and cancel
the close command so that BeforeUpdate event code manages any error messages
and prompts displayed to the user?

Thanks for any help you can offer.

Regards,

Tesa
 
M

Marshall Barton

TESA0_4 said:
If the intrinsic close command button at the top right of a form is clicked
when a record is incomplete, the usual Access error messages are displayed.
How can I detect that the user has clicked the form close button and cancel
the close command so that BeforeUpdate event code manages any error messages
and prompts displayed to the user?


See if you can get what you want from the form's Unload
event.
 
D

Dale Fye

Tesa,

I generally include the following in most of my forms.

1. I add a module level declaration statement (at the top of the code
window, right below the Option Explicit statement) that declares a form wide
variable

Dim AllowClose as Boolean

2. Then, in the forms Open event, I set AllowClose = False

3. Then, in the forms Unload Event, I include code to handle the error:

Private Sub Form_Unload(Cancel As Integer)

If AllowClose = False then
msgbox "Click the close button to close this form"
if me.visible = false then me.visible = True
Cancel = True
Else
Cancel = False 'don't really need this line
Endif

End Sub

4. Lastly, in the code behind my forms close button (cmd_Close), I set
AllowClose = true.

This will pervent the user from closing the form by using either the X
button on the form, or the X button on the Access window.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top