Focus set to subform control


D

Darrell

The following code is in the AfterUpdate event of a combo box on a main
form:

Private Sub comboboxOnMainForm_AfterUpdate()

'Enable subform
Me!subform.Enabled = True

Me!subform!control1 = "Value1"
Me!subform!control2 = "Value2"
Me!subform!control3 = "Value3"
Me!subform!control4.SetFocus

End Sub


The above code, running on a main form's combo box, executes without
complaint. But, the focus ends up squarely in the original combo box.
There is not code that runs after this. How and why does the SetFocus
executed in the last line seem to have no effect? And, obviously, how
can I remedy this?

Thank you in advance for any help!

Darrell
 
Ad

Advertisements

D

Dirk Goldgar

In
Darrell said:
The following code is in the AfterUpdate event of a combo box on a
main form:

Private Sub comboboxOnMainForm_AfterUpdate()

'Enable subform
Me!subform.Enabled = True

Me!subform!control1 = "Value1"
Me!subform!control2 = "Value2"
Me!subform!control3 = "Value3"
Me!subform!control4.SetFocus

End Sub


The above code, running on a main form's combo box, executes without
complaint. But, the focus ends up squarely in the original combo box.
There is not code that runs after this. How and why does the SetFocus
executed in the last line seem to have no effect? And, obviously, how
can I remedy this?

Thank you in advance for any help!

Darrell

The subform and the main form both have their own "active controls".
You have to both set focus to the control on the subform and set focus
to the subform itself:

Me!subform.SetFocus
Me!subform!control4.SetFocus
 

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