Close a form when it loses focus


P

PayeDoc

Hello All

Is it possible to make a form close as soon as the user clicks elsewhere on
the screen? The form in question is a trivial popup form that is best shown
in datasheet view, so I can't add a button. I know the user could close it
with the 'X' in the top-right corner, but for other reasons it would be much
better if I could force it to close as soon as they click elsewhere. I have
tried adding the following OnLostFocus event to the form, but nothing
happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate post?): when I open
[frm contacts] via a button on another form, I can't then go into [frm
contacts]'s design view: doing right-click on it just brings up options to
Move, Size, Minimise, Maximise and Close. If I open [frm contacts] from the
main database window right-click does bring up the expected options (Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 
Ad

Advertisements

J

Jeanette Cunningham

You could put this code
DoCmd.Close acForm, "[frm contacts]", acSaveYes
..... on the Activate event of the other forms that will be open and visible
at the same time that the popup is open.


In A2007, you can go Alt+V+D to put a form in normal view into design view.
This will not work in A2003.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
P

PayeDoc

Hello Jeanette

Many thanks for your reply, and for your suggestion to use the Activate
event of the other forms: I wil try that and report back if there are any
problems.

I am using A2K, so obviously Alt+V+D is no good here: but why am I prevented
from opening the form in design view using the normal right-click option -
this works for other forms I have?

Thanks again for your help.
Les


Jeanette Cunningham said:
You could put this code
DoCmd.Close acForm, "[frm contacts]", acSaveYes
.... on the Activate event of the other forms that will be open and visible
at the same time that the popup is open.


In A2007, you can go Alt+V+D to put a form in normal view into design view.
This will not work in A2003.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


PayeDoc said:
Hello All

Is it possible to make a form close as soon as the user clicks elsewhere
on
the screen? The form in question is a trivial popup form that is best
shown
in datasheet view, so I can't add a button. I know the user could close it
with the 'X' in the top-right corner, but for other reasons it would be
much
better if I could force it to close as soon as they click elsewhere. I
have
tried adding the following OnLostFocus event to the form, but nothing
happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate post?): when I open
[frm contacts] via a button on another form, I can't then go into [frm
contacts]'s design view: doing right-click on it just brings up options to
Move, Size, Minimise, Maximise and Close. If I open [frm contacts] from
the
main database window right-click does bring up the expected options
(Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 
R

Rob Parker

I haven't tested this, but I would expect it to work. Simply put the
DoCmd.Close code in the Deactivate event of the form that it applies to.

HTH,

Rob
 
R

Rob Parker

Following up my own post ...

There's also the form's LostFocus event - which is probably the better
choice ;-)

Rob


Rob Parker said:
I haven't tested this, but I would expect it to work. Simply put the
DoCmd.Close code in the Deactivate event of the form that it applies to.

HTH,

Rob


PayeDoc said:
Hello All

Is it possible to make a form close as soon as the user clicks elsewhere
on
the screen? The form in question is a trivial popup form that is best
shown
in datasheet view, so I can't add a button. I know the user could close
it
with the 'X' in the top-right corner, but for other reasons it would be
much
better if I could force it to close as soon as they click elsewhere. I
have
tried adding the following OnLostFocus event to the form, but nothing
happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate post?): when I
open
[frm contacts] via a button on another form, I can't then go into [frm
contacts]'s design view: doing right-click on it just brings up options
to
Move, Size, Minimise, Maximise and Close. If I open [frm contacts] from
the
main database window right-click does bring up the expected options
(Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 
P

PayeDoc

Hi Rob

Many thanks for your suggestions. In fact I had tried using the OnLostFocus
event (see my original post), but this didn't work. I will try the
Deactivate event!

Thanks again
Les

Rob Parker said:
Following up my own post ...

There's also the form's LostFocus event - which is probably the better
choice ;-)

Rob


Rob Parker said:
I haven't tested this, but I would expect it to work. Simply put the
DoCmd.Close code in the Deactivate event of the form that it applies to.

HTH,

Rob


PayeDoc said:
Hello All

Is it possible to make a form close as soon as the user clicks elsewhere
on
the screen? The form in question is a trivial popup form that is best
shown
in datasheet view, so I can't add a button. I know the user could close
it
with the 'X' in the top-right corner, but for other reasons it would be
much
better if I could force it to close as soon as they click elsewhere. I
have
tried adding the following OnLostFocus event to the form, but nothing
happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate post?): when I
open
[frm contacts] via a button on another form, I can't then go into [frm
contacts]'s design view: doing right-click on it just brings up options
to
Move, Size, Minimise, Maximise and Close. If I open [frm contacts] from
the
main database window right-click does bring up the expected options
(Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 
Ad

Advertisements

D

Dirk Goldgar

PayeDoc said:
Hi Rob

Many thanks for your suggestions. In fact I had tried using the
OnLostFocus
event (see my original post), but this didn't work. I will try the
Deactivate event!


A form's GotFocus and LostFocus events only fire if there are no controls on
the form that can receive the focus. Otherwise, a control gets/loses the
focus, not the form itself.
 
B

Bob Quintal

Hello Jeanette

Many thanks for your reply, and for your suggestion to use the
Activate event of the other forms: I wil try that and report back
if there are any problems.

I am using A2K, so obviously Alt+V+D is no good here: but why am I
prevented from opening the form in design view using the normal
right-click option - this works for other forms I have?

Thanks again for your help.
Les
Does your form have the Popup or Dialog property set to yes? or does
the code that opens the form set the Popup or Dialog property when it
opens the form?

That can cause the issue you describe.

Bob

Jeanette Cunningham said:
You could put this code
DoCmd.Close acForm, "[frm contacts]", acSaveYes
.... on the Activate event of the other forms that will be open
and visible
at the same time that the popup is open.


In A2007, you can go Alt+V+D to put a form in normal view into
design view.
This will not work in A2003.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


PayeDoc said:
Hello All

Is it possible to make a form close as soon as the user clicks
elsewhere on
the screen? The form in question is a trivial popup form that
is best shown
in datasheet view, so I can't add a button. I know the user
could close it
with the 'X' in the top-right corner, but for other reasons it
would be much
better if I could force it to close as soon as they click
elsewhere. I have
tried adding the following OnLostFocus event to the form, but
nothing happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate post?):
when I open
[frm contacts] via a button on another form, I can't then go
into [frm contacts]'s design view: doing right-click on it just
brings up options to
Move, Size, Minimise, Maximise and Close. If I open [frm
contacts] from the
main database window right-click does bring up the expected
options (Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 
P

PayeDoc

Hello Bob

Many thanks for your reply.

The form does have 'popup' set to yes, but I have other such forms where
right-click does bring up the Design view, etc., options.

What else can it be?

Thanks again
Les


Bob Quintal said:
Hello Jeanette

Many thanks for your reply, and for your suggestion to use the
Activate event of the other forms: I wil try that and report back
if there are any problems.

I am using A2K, so obviously Alt+V+D is no good here: but why am I
prevented from opening the form in design view using the normal
right-click option - this works for other forms I have?

Thanks again for your help.
Les
Does your form have the Popup or Dialog property set to yes? or does
the code that opens the form set the Popup or Dialog property when it
opens the form?

That can cause the issue you describe.

Bob

Jeanette Cunningham said:
You could put this code
DoCmd.Close acForm, "[frm contacts]", acSaveYes
.... on the Activate event of the other forms that will be open
and visible
at the same time that the popup is open.


In A2007, you can go Alt+V+D to put a form in normal view into
design view.
This will not work in A2003.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Hello All

Is it possible to make a form close as soon as the user clicks
elsewhere on
the screen? The form in question is a trivial popup form that
is best shown
in datasheet view, so I can't add a button. I know the user
could close it
with the 'X' in the top-right corner, but for other reasons it
would be much
better if I could force it to close as soon as they click
elsewhere. I have
tried adding the following OnLostFocus event to the form, but
nothing happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate post?):
when I open
[frm contacts] via a button on another form, I can't then go
into [frm contacts]'s design view: doing right-click on it just
brings up options to
Move, Size, Minimise, Maximise and Close. If I open [frm
contacts] from the
main database window right-click does bring up the expected
options (Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 
B

Bob Quintal

Hello Bob

Many thanks for your reply.

The form does have 'popup' set to yes, but I have other such forms
where right-click does bring up the Design view, etc., options.

What else can it be?

What about the 'modal' property?
How is the form being opened? could there be a setting of modal
there?
What is in the 'menubar' and 'toolbar' properties of this form?

Bob
Thanks again
Les


Bob Quintal said:
Hello Jeanette

Many thanks for your reply, and for your suggestion to use the
Activate event of the other forms: I wil try that and report
back if there are any problems.

I am using A2K, so obviously Alt+V+D is no good here: but why
am I prevented from opening the form in design view using the
normal right-click option - this works for other forms I have?

Thanks again for your help.
Les
Does your form have the Popup or Dialog property set to yes? or
does the code that opens the form set the Popup or Dialog
property when it opens the form?

That can cause the issue you describe.

Bob

message You could put this code
DoCmd.Close acForm, "[frm contacts]", acSaveYes
.... on the Activate event of the other forms that will be
open and
visible
at the same time that the popup is open.


In A2007, you can go Alt+V+D to put a form in normal view into
design
view.
This will not work in A2003.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria
Australia


Hello All

Is it possible to make a form close as soon as the user
clicks elsewhere on
the screen? The form in question is a trivial popup form
that is best shown
in datasheet view, so I can't add a button. I know the user
could close
it
with the 'X' in the top-right corner, but for other reasons
it would be much
better if I could force it to close as soon as they click
elsewhere. I have
tried adding the following OnLostFocus event to the form,
but nothing happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate
post?): when I
open
[frm contacts] via a button on another form, I can't then go
into [frm contacts]'s design view: doing right-click on it
just brings up options
to
Move, Size, Minimise, Maximise and Close. If I open [frm
contacts] from the
main database window right-click does bring up the expected
options (Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 
Ad

Advertisements

P

PayeDoc

Hello Bob

Thanks for your further reply.
'Modal' is also set to No!
I think I've sussed it though: the form was opening in datasheet view - when
I open it in form view, right-click gives the expected options!!

Thanks again for your help
Les


Bob Quintal said:
Hello Bob

Many thanks for your reply.

The form does have 'popup' set to yes, but I have other such forms
where right-click does bring up the Design view, etc., options.

What else can it be?

What about the 'modal' property?
How is the form being opened? could there be a setting of modal
there?
What is in the 'menubar' and 'toolbar' properties of this form?

Bob
Thanks again
Les


Bob Quintal said:
Hello Jeanette

Many thanks for your reply, and for your suggestion to use the
Activate event of the other forms: I wil try that and report
back if there are any problems.

I am using A2K, so obviously Alt+V+D is no good here: but why
am I prevented from opening the form in design view using the
normal right-click option - this works for other forms I have?

Thanks again for your help.
Les

Does your form have the Popup or Dialog property set to yes? or
does the code that opens the form set the Popup or Dialog
property when it opens the form?

That can cause the issue you describe.

Bob



message You could put this code
DoCmd.Close acForm, "[frm contacts]", acSaveYes
.... on the Activate event of the other forms that will be
open and
visible
at the same time that the popup is open.


In A2007, you can go Alt+V+D to put a form in normal view into
design
view.
This will not work in A2003.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria
Australia


Hello All

Is it possible to make a form close as soon as the user
clicks elsewhere on
the screen? The form in question is a trivial popup form
that is best shown
in datasheet view, so I can't add a button. I know the user
could close
it
with the 'X' in the top-right corner, but for other reasons
it would be much
better if I could force it to close as soon as they click
elsewhere. I have
tried adding the following OnLostFocus event to the form,
but nothing happened!

DoCmd.Close acForm, "[frm contacts]", acSaveYes

Second question (or does this need to be in a separate
post?): when I
open
[frm contacts] via a button on another form, I can't then go
into [frm contacts]'s design view: doing right-click on it
just brings up options
to
Move, Size, Minimise, Maximise and Close. If I open [frm
contacts] from the
main database window right-click does bring up the expected
options (Design
view, etc.). What's going on?

Hope someone can help.
Thanks
Les
 

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