Setting Focus to a Field on a Sub-Form

  • Thread starter Thread starter Anthony Viscomi
  • Start date Start date
A

Anthony Viscomi

I have a Main frm, which uses Tabs. Within one of the tabbed pages there is
a sub-form, I would like the focus to be set to a field within that sub-form
when the user clicks on that particuliar tab. Obviously this needs to be
done within the Tab Control "on click" event, but I've been unsuccessful in
making it work. Any thoughts?

Thanks!
Anthony Viscomi
 
try using the TabCtl's Change event. a tab control's value is the value of
the Index property of the current tab page. so if, for example, the Index
value of the page in question is 5, then you can run the code as

If Me!TabCtlName = 5 Then
'put here the code to set focus on the subform and its' specific
control
End If

hth
 
'put here the code to set focus on the subform and its' specific

Something like the following:

Me.YourSubformControl.Form!YourControl.SetFocus


Luiz Cláudio C. V. Rocha
São Paulo - Brazil
 
Remember that you must set focus to the subform control first, and then to
the control on the subform:

Me.YourSubformControl.SetFocus
Me.YourSubformControl!YourControlOnSubform.SetFocus
 
I've tried this and it did not work; here is what I have:

Me.subfrm_OrderB.Quantity.SetFocus
 
Anthony Viscomi said:
I've tried this and it did not work; here is what I have:

Me.subfrm_OrderB.Quantity.SetFocus

Did you move your code out of the Click event of the page? That event is NOT
what you think it is. You have to use the Change event of the TabControl.
 
Tried that:
Private Sub TabCtl3_Change()
subfrm_OrderB.Quantity.SetFocus
End Sub

I received a "Method not found error"
It seems as if I can't get the focus to the subfrm before moving it to the
Quantity field.
 
The "Form" property is missing:

Me.YourSubformControl.SetFocus
Me.YourSubformControl.Form!YourControl.SetFocus


Luiz Cláudio C. V. Rocha
São Paulo - Brazil
 
Anthony Viscomi said:
Tried that:
Private Sub TabCtl3_Change()
subfrm_OrderB.Quantity.SetFocus
End Sub

It was indicated earlier that you need two statements. First one that sets
focus to the subform control followed by a second one that set focus to the
specific control within the subform. The
code you just posted does not do that.

subfrm_OrderB.SetFocus
subfrm_OrderB.Form.Quantity.SetFocus

You also need to test the Value property of the TabControl so your code will
only run when a specific TabPage is selected. As you have it now the code will
run when you change to *any* page. Not what you want I'm sure.
 
This works:
Private Sub TabCtl3_Change()
subfrm_OrderB.SetFocus
subfrm_OrderB.Form.Quantity.SetFocus
End Sub

But because it is triggered on the TabCtl3 Change Event I am unable to leave
that tabbed page.

I've tried this:
Private Sub Page7_Click()
subfrm_OrderB.SetFocus
subfrm_OrderB.Form.Quantity.SetFocus
End Sub

Where Page7 is actually the page taht contains the subfrm, but that doesn't
work either.
 
hon, i told you how to do it in my previous post. and then Rick told you
again.

a tab control's value is the value of the Index property of the current tab
page. so if, for example, the Index value of the page in question is 5, then
you can run the code as

If Me!TabCtl3 = 5 Then
'put here the code to set focus on the subform and its' specific
control
End If

so look at the Index property of page 7 of tabctl3, and use that value to
replace the "5" in the code above.

then insert the SetFocus statements that you've already found to work.

subfrm_OrderB.SetFocus
subfrm_OrderB.Form.Quantity.SetFocus
 
Thanks All! Tina's solution worked great.
tina said:
hon, i told you how to do it in my previous post. and then Rick told you
again.

a tab control's value is the value of the Index property of the current tab
page. so if, for example, the Index value of the page in question is 5, then
you can run the code as

If Me!TabCtl3 = 5 Then
'put here the code to set focus on the subform and its' specific
control
End If

so look at the Index property of page 7 of tabctl3, and use that value to
replace the "5" in the code above.

then insert the SetFocus statements that you've already found to work.

subfrm_OrderB.SetFocus
subfrm_OrderB.Form.Quantity.SetFocus
 
..Form is not required in the second code step for referencing a control on
the subform.

But it's not harmful to include it!
 
Back
Top