Event on close

R

Robert

Is there an event which fires when you X out of a form? I looked at the On
Close event of the form. I have a cancel button on the form which closes
the form. On Close gets hit when I click on this button. But I don't want
to hit On Close when I click on my button. Is there an event or a way to
trap the clicking of the X at the upper right-hand corner of the form that
won't also get hit every time the form is closed? Would like to avoid using
switches.

Robert
 
D

Douglas J. Steele

No, there's no separate event.

The normal approach is to set a module-level variable to False when they
open the form, and set it to True when they close the form properly. In that
way, you can check the value of the variable in the Close event and act
accordingly.
 
J

J_Goddard via AccessMonster.com

I'm a bit confused about what you are asking here;

if you don't want users to close the form with the upper-right X, you can set
the Close Button property of the form to "No". This will disable the X,
though it will still be visible.

Is this what you want?

If the Cancel button closes the form, then the On Close event will fire -
always. If the On Close event contains code that you do not want to execute
if the "Cancel" button is clicked, you can check for the Cancel button with
the Previouscontrol Property:

if Screen.previouscontrol.name = "CancelButton" then
... whatever code you need
else
... code if X is clicked
endif

HTH

John
 
R

Robert

I think you got it right. For now I'm going to disable the X. Thanks for
the suggestions.
 
R

Robert

John,
When I set the form's Close Button property to No, the close button still
works. What gives? I'm using Access 2002.
Robert
 
J

J_Goddard via AccessMonster.com

Good question. Does setting the setting the Close Button property to No
"grey out" (i.e. disable) the X at the upper right? If not, I have no idea
why it would not. I use Access 2000, so maybe there is a difference.

Experts?

John

John,
When I set the form's Close Button property to No, the close button still
works. What gives? I'm using Access 2002.
Robert
I'm a bit confused about what you are asking here;
[quoted text clipped - 34 lines]
 
R

Robert

No, it's not greyed out.

J_Goddard via AccessMonster.com said:
Good question. Does setting the setting the Close Button property to No
"grey out" (i.e. disable) the X at the upper right? If not, I have no
idea
why it would not. I use Access 2000, so maybe there is a difference.

Experts?

John

John,
When I set the form's Close Button property to No, the close button still
works. What gives? I'm using Access 2002.
Robert
I'm a bit confused about what you are asking here;
[quoted text clipped - 34 lines]
 
J

J_Goddard via AccessMonster.com

Puzzling. I cannot reproduce this problem in 2003, even with a brand new
form with all default properties. Try creating a brand new form, with only a
command button on it. If you use the command button wizard, have it set the
action of the command button to close the form.

Then set the Close Button property of the form to "No". Does that work, i.e.
disable the X at the upper right?

John

No, it's not greyed out.
Good question. Does setting the setting the Close Button property to No
"grey out" (i.e. disable) the X at the upper right? If not, I have no
[quoted text clipped - 14 lines]
 
R

Robert

I created a form with a command button that closes the form on it and I set
the form's close button property to No, but the close button still works.

J_Goddard via AccessMonster.com said:
Puzzling. I cannot reproduce this problem in 2003, even with a brand new
form with all default properties. Try creating a brand new form, with
only a
command button on it. If you use the command button wizard, have it set
the
action of the command button to close the form.

Then set the Close Button property of the form to "No". Does that work,
i.e.
disable the X at the upper right?

John

No, it's not greyed out.
Good question. Does setting the setting the Close Button property to No
"grey out" (i.e. disable) the X at the upper right? If not, I have no
[quoted text clipped - 14 lines]
 

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