Problems moving focus to another form

G

Guest

In an Access 2000 application, I have a main form (RegForm) that opens a
popup form in certain specified circumstances. I want the focus to return to
a control (SurnameCombo) on the main form as soon as the popup has displayed
the required data, while leaving the popup open. However I am having trouble
making this focus switch happen automatically.

Just as an experiment, I attached the following code to a temporary command
button on the Popup form and it works fine.
Forms![RegForm].SetFocus
Forms![RegForm]![SurnameCombo].SetFocus

However, if I use the same code on a variety of the Popup form's events
(i.e. Open, AfterUpdate and GotFocus), nothing happens. Focus remains with
the Popup form. Note that RegForm is already open.

No doubt I am making a very basic error (probably related to the Popup form
not yet being ready to relinquish focus). Any suggestions?

David
 
G

Guest

David,

Take a look at the tab order of your popup form to determine the control
that if the first control on this form (gets the focus when the form loads)
and place your code in the Got Focus event of that control.

This will work to cause the focus back to the first form. However, be aware
that doing this will cause this code to fire every time the popup form
receives the focus to the first control. Not knowing your specific needs,
you may need to have some way that the use can actually use the popup form.
 
G

Guest

Mr B,
The Popup form would not normally have any enabled controls to receive the
focus (the popup is only there to provide information), however it currently
has the temporary command button I mentioned in my original post. I therefore
added a SetFocus command in the Popup form's Open event to move focus to this
button and then added the code to move focus to my other form in the command
button's GotFocus event.

I fully expected this to work as you described. Unfortunately, it doesn't
have any effect. Focus remains with the Popup form.

David



Mr B said:
David,

Take a look at the tab order of your popup form to determine the control
that if the first control on this form (gets the focus when the form loads)
and place your code in the Got Focus event of that control.

This will work to cause the focus back to the first form. However, be aware
that doing this will cause this code to fire every time the popup form
receives the focus to the first control. Not knowing your specific needs,
you may need to have some way that the use can actually use the popup form.

--
HTH

Mr B
askdoctoraccess dot com


David Anderson said:
In an Access 2000 application, I have a main form (RegForm) that opens a
popup form in certain specified circumstances. I want the focus to return to
a control (SurnameCombo) on the main form as soon as the popup has displayed
the required data, while leaving the popup open. However I am having trouble
making this focus switch happen automatically.

Just as an experiment, I attached the following code to a temporary command
button on the Popup form and it works fine.
Forms![RegForm].SetFocus
Forms![RegForm]![SurnameCombo].SetFocus

However, if I use the same code on a variety of the Popup form's events
(i.e. Open, AfterUpdate and GotFocus), nothing happens. Focus remains with
the Popup form. Note that RegForm is already open.

No doubt I am making a very basic error (probably related to the Popup form
not yet being ready to relinquish focus). Any suggestions?

David
 
G

Guest

David,

I assumed from your original posting that you did not have the modal and
popup properties of your form set to Yes becasue you indicated that you had
been able to make the code work using a command button. Do you have either
of these properties set to Yes?

In cases where I do not want a specific control to show to have the focus, I
have been known to create a special text box and set its properties like:

Name: txtHoldCursor
Background: same as area of form where it is placed
Left = 0
Width = 0
Back Style = transparant
Special Effect = flat
Boder Style = Transparent

These setting should make the control to not be seen (not even the cursor)
when the form opens but allow the control to receive the focus. You can
place your code in the Got Focus of this control.

Make this control the first control in the Tab Order list.

This will cause this control to receive the focus.
--
HTH

Mr B
askdoctoraccess dot com


David Anderson said:
Mr B,
The Popup form would not normally have any enabled controls to receive the
focus (the popup is only there to provide information), however it currently
has the temporary command button I mentioned in my original post. I therefore
added a SetFocus command in the Popup form's Open event to move focus to this
button and then added the code to move focus to my other form in the command
button's GotFocus event.

I fully expected this to work as you described. Unfortunately, it doesn't
have any effect. Focus remains with the Popup form.

David



Mr B said:
David,

Take a look at the tab order of your popup form to determine the control
that if the first control on this form (gets the focus when the form loads)
and place your code in the Got Focus event of that control.

This will work to cause the focus back to the first form. However, be aware
that doing this will cause this code to fire every time the popup form
receives the focus to the first control. Not knowing your specific needs,
you may need to have some way that the use can actually use the popup form.

--
HTH

Mr B
askdoctoraccess dot com


David Anderson said:
In an Access 2000 application, I have a main form (RegForm) that opens a
popup form in certain specified circumstances. I want the focus to return to
a control (SurnameCombo) on the main form as soon as the popup has displayed
the required data, while leaving the popup open. However I am having trouble
making this focus switch happen automatically.

Just as an experiment, I attached the following code to a temporary command
button on the Popup form and it works fine.
Forms![RegForm].SetFocus
Forms![RegForm]![SurnameCombo].SetFocus

However, if I use the same code on a variety of the Popup form's events
(i.e. Open, AfterUpdate and GotFocus), nothing happens. Focus remains with
the Popup form. Note that RegForm is already open.

No doubt I am making a very basic error (probably related to the Popup form
not yet being ready to relinquish focus). Any suggestions?

David
 
G

Guest

The Popup form has the Popup property set to Yes (Modal is No), but I'm not
quite sure what relevance that has to using command buttons.

While I understand your method for using an invisible control to handle the
SetFocus code, the fact remains that the code is not even working for me via
a visible control.

David
 
G

Guest

David,

I'm not sure what is causing this behavior. In my testing here, having the
Popup set to true only causes the form to remain on top of all other forms.
It does not prevent the code from running and completing as designed.

I tested with only three lines in the click event of a command button:

DoCmd.OpenForm "form1"
Forms!form2.SetFocus
Forms!form2.cmdButtonName.SetFocus

It works as it is designed to work.

You might need to post your code that you are using to do the same thing.
 
G

Guest

Unwittingly, you solved my problem in your sample code. The key was to put
the SetFocus statements in the primary form. As indicated in my earlier
posts, I was attaching my SetFocus statements to various popup form events,
and I'm guessing that there were later popup form events that caused focus to
instantly return to the popup form.

Thanks for the help. All is now well.

David
 

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