Targeting a textbox in a subform that's in TAB Control

J

Jeff

Hi All,

I have a form with a TabControl that has 4 Tabs.

On each tab is a different subform.

The form 'fmStudentGrades'is opened automatically by another form if 3
specific fields have not been filled - lets call them txtbox1, txtbox2
and txtbox3. (After a certain date they need to be filled.)

I'd like the code that opens the form to change the backgrouncolor of
these boxes and set the focus to the field 'txtbox1' They are all on the
3rd Tab called 'Results' in a subform called 'sbfEnglish'

I just can't seem to get to target the boxes at all. I can target the
Tab 'Results' with:

Forms![Add Aluno 2]!Results.SetFocus

But I can't get to target the txtboxes in the Tab 'Rsults'

Any ideas greatly appreciated,

jeff
 
W

Wayne Morgan

A couple of things here.

1) The syntax to refer to a control on a subform from the parent form (even
though the subform is on a tab control, it is still considered to be a
control on the parent (main) form).

Me.NameOfSubformControl.Form.NameOfControlOnSubform

2) To set the focus to a control on a subform is a two step process. You
first have to set the focus to the subform control that holds the subform,
then to the control on the subform.

Me.NameOfSubformControl.SetFocus
Me.NameOfSubformControl.Form.NameOfControlOnSubform.SetFocus

3) There is a bug in the tab control that may not let you see that the focus
was set to the correct control if you try to set that focus in the tab
control's change event. If this happens, then you can move the focus to
another form then close that other form, the focus will then appear to be on
the correct control in the subform. You can try to do this by creating a
"dummy" form, turning Echo off, opening the "dummy" form, closing the
"dummy" form, then turning Echo on again. With Echo turned off, the user
doesn't see what is happening. In testing tonight, this appeared to not be
necessary, but I've seen this before and it was necessary.

It is possible that I'm not remembering the correct details to cause the
problem mentioned in #3. You may just have to try it and see if it works for
you.
 
W

Wayne Morgan

A further explanation:

A subform isn't open as a form. It is an object on the main form being held
in a container control called a subform control. This control can get and
lose the focus, not the form it holds. Controls on the subform can also get
and lose the focus.
 
J

Jeff

Wayne said:
A further explanation:

A subform isn't open as a form. It is an object on the main form being held
in a container control called a subform control. This control can get and
lose the focus, not the form it holds. Controls on the subform can also get
and lose the focus.

Wayne,

Got it!

Thanks for the help,

Jeff
 

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