How to reference a listbox on a Subform>TabPage>MainForm?

R

Robin

Hi

I'm trying to reference a List Box which is on a subform, on a page of a tab
control, which is on a main form. I'm trying to use the List Box MouseMove
event to SetFocus on the list box and whichever syntax I try for the
reference the SetFocus gets ignored but without errors. (The MouseMove bit
is ok, but focus stays where it was previously.)

I've so far tried:

Forms!MainForm!SubForm!ListBox.SetFocus
Forms!MainForm!TabControl!SubForm!ListBox.SetFocus
Me!ListBox.SetFocus

Do I need to specifically reference the page involved, and if so how?

Regards

Robin
 
R

Rick Brandt

Robin said:
Hi

I'm trying to reference a List Box which is on a subform, on a page
of a tab control, which is on a main form. I'm trying to use the
List Box MouseMove event to SetFocus on the list box and whichever
syntax I try for the reference the SetFocus gets ignored but without
errors. (The MouseMove bit is ok, but focus stays where it was
previously.)
I've so far tried:

Forms!MainForm!SubForm!ListBox.SetFocus
Forms!MainForm!TabControl!SubForm!ListBox.SetFocus
Me!ListBox.SetFocus

Do I need to specifically reference the page involved, and if so how?

The TabControl doesn't enter into this at all, but you need to specify that you
want the form object inside the siubform control...

Forms!MainForm!SubForm.Form!ListBox.SetFocus

NOTE: The above uses the name of the subform *control* which is not guaranteed
to have the same name as the form inside it.
 
R

Robin

Rick Brandt said:
The TabControl doesn't enter into this at all, but you need to specify
that you want the form object inside the siubform control...

Forms!MainForm!SubForm.Form!ListBox.SetFocus

NOTE: The above uses the name of the subform *control* which is not
guaranteed to have the same name as the form inside it.
Thank you Rick. I have now correctly referenced the ListBox (and I now
realise that a few of the options I tried previously were also working).
The real issue seems to be the ListBox not accepting focus. It does by
clicking it but not through SetFocus. I tried substituting a change of
ForeColor in the MouseMove event - this works. It's just SetFocus that
doesn't.

Regards

Robin
 
R

Rick Brandt

Robin said:
Thank you Rick. I have now correctly referenced the ListBox (and I
now realise that a few of the options I tried previously were also
working). The real issue seems to be the ListBox not accepting focus.
It does by clicking it but not through SetFocus. I tried
substituting a change of ForeColor in the MouseMove event - this
works. It's just SetFocus that doesn't.

Often you have to set focus to the subform control first and then follow that
with a line of code to set focus to the desired control.

Forms!MainForm!SubForm.SetFocus
Forms!MainForm!SubForm.Form!ListBox.SetFocus
 
R

Robin

Rick Brandt said:
Often you have to set focus to the subform control first and then follow
that with a line of code to set focus to the desired control.

Forms!MainForm!SubForm.SetFocus
Forms!MainForm!SubForm.Form!ListBox.SetFocus
Thank you very much Rick - perfect! It's not that intuitive is it :)
 
Top