Setting Focus to a Field on a Sub-Form

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
 
T

tina

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
 
L

Luiz Cláudio

'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
 
K

Ken Snell [MVP]

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
 
A

Anthony Viscomi

I've tried this and it did not work; here is what I have:

Me.subfrm_OrderB.Quantity.SetFocus
 
R

Rick Brandt

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.
 
A

Anthony Viscomi

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.
 
L

Luiz Cláudio

The "Form" property is missing:

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


Luiz Cláudio C. V. Rocha
São Paulo - Brazil
 
R

Rick Brandt

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.
 
A

Anthony Viscomi

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.
 
T

tina

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
 
A

Anthony Viscomi

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
 
K

Ken Snell [MVP]

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

But it's not harmful to include it!
 
G

Guest

Anthony Viscomi escribió:
I've tried this and it did not work; here is what I have:

Me.subfrm_OrderB.Quantity.SetFocus
quiero recibir spam y no me importa de donde
 

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