Close form when clicking on another form

  • Thread starter Thread starter magmike
  • Start date Start date
M

magmike

I have a quick little pop-up that comes up to give a little more
detail when clicking on the name of a contact. However, I've been
trying to figure out how to close that pop up form when the user
clicks elsewhere on the main form.

Anyideas?

magmike
 
magmike said:
I have a quick little pop-up that comes up to give a little more
detail when clicking on the name of a contact. However, I've been
trying to figure out how to close that pop up form when the user
clicks elsewhere on the main form.

Anyideas?

magmike

Put this code in your popup's OnLoad event, after any initialisation code
you may already have there.

Do
DoEvents
Loop While Screen.ActiveForm.Name = Me.Name
DoCmd.Close acForm, Me.Name

The DoEvents allows other form events to fire so your form behaves normally,
and the loop will terminate as soon as the popup loses focus (by the user
clicking outside it). The next command closes the popup.
 
Another approach would be to bring that form up in "dialog" mode, and put a
<Close> button on it. That way, the user couldn't "leave" the popup until
s/he explicitly closed it.

The potential problem with having a form disappear on its own is that users
can get confused. They didn't close it themselves, so it must be here
somewhere...?!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
magmike said:
I have a quick little pop-up that comes up to give a little more
detail when clicking on the name of a contact. However, I've been
trying to figure out how to close that pop up form when the user
clicks elsewhere on the main form.

Anyideas?

magmike

Put this code in your popup's OnLoad event, after any initialisation code
you may already have there.

Do
DoEvents
Loop While Screen.ActiveForm.Name = Me.Name
DoCmd.Close acForm, Me.Name

The DoEvents allows other form events to fire so your form behaves normally,
and the loop will terminate as soon as the popup loses focus (by the user
clicking outside it). The next command closes the popup.
 
Another approach would be to bring that form up in "dialog" mode, and put a
<Close> button on it. That way, the user couldn't "leave" the popup until
s/he explicitly closed it.

The potential problem with having a form disappear on its own is that users
can get confused. They didn't close it themselves, so it must be here
somewhere...?!

Regards

Jeff Boyce
Microsoft Office/Access MVP






- Show quoted text -

I know that this pop up form is technically a form, but the user
doesn't. The form is designed to look and act like a tool tip. The
only difference is it must be clicked on. It's purpose is to expand
the field when there is more information than can be displayed in the
space alotted. AND, i'm trying to minimize on extra forms being
opened.
 
Maybe I'm missing something...

"... it must be clicked on" makes it sound like the user is already clicking
on it. Could you use the Click event to close it?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Put this code in your popup's OnLoad event, after any initialisation code
you may already have there.

Do
DoEvents
Loop While Screen.ActiveForm.Name = Me.Name
DoCmd.Close acForm, Me.Name

The DoEvents allows other form events to fire so your form behaves normally,
and the loop will terminate as soon as the popup loses focus (by the user
clicking outside it). The next command closes the popup.

I am having a problem getting this code to work. Understanding that my
forms name is ContactDetailToolTip how would you modify this code, if
at all (which non-modification did not work for me)?
 
magmike said:
I am having a problem getting this code to work. Understanding that my
forms name is ContactDetailToolTip how would you modify this code, if
at all (which non-modification did not work for me)?

Hmm. I must admit that I adapted that code from my routine that pops a form
directly under a control, and the code actually executes in a standard
module. Although I thought it ought to execute from the form's class module,
obviously I'm wrong.

So in order to get it working, put the code in the procedure that opens your
popup, if you have one. Otherwise you'll have to create one.

strPopup = "ContactDetailToolTip"
DoCmd.OpenForm strPopup
Do
DoEvents
Loop While Screen.ActiveForm.Name = strPopup
DoCmd.Close acForm, strPopup
 
Hmm. I must admit that I adapted that code from my routine that pops a form
directly under a control, and the code actually executes in a standard
module. Although I thought it ought to execute from the form's class module,
obviously I'm wrong.

So in order to get it working, put the code in the procedure that opens your
popup, if you have one. Otherwise you'll have to create one.

strPopup = "ContactDetailToolTip"
DoCmd.OpenForm strPopup
Do
DoEvents
Loop While Screen.ActiveForm.Name = strPopup
DoCmd.Close acForm, strPopup- Hide quoted text -

- Show quoted text -

Thanks, that worked. But, Jeff was right. It is confusing. There goes
another one of my "great" ideas!

I do appreciate your coming to the task, though. Thanks a bunch!
 
Back
Top