Refering to Treeview on form from subform using control name and index

Z

zz

Hi,
I am able to refer to a Treeview control on the main form using its
control index in the controls collection of the form; but I can not
refer to it by name. i.e. :

In the load event for the subform:
[ok --->] Set objTvwOnMainForm =
[Forms]![MainFrom].[Form].Controls(0).Object

[NOT ok --->]Set objTvwOnMainForm =
[Forms]![MainFrom].[Form].Controls("tvwExample").Object

With the error message: Run-time error '2465' can't find the field
'tvwExample' refered to in your expression. I have double checked the
name but no expected results.

I have no problem using index but I guess there is something like
"subforms load prior to forms" thing that I don't know and also it is
bad idea the code be index dependent rather than name dependent. So any
insight is appreciated.

Hamid
 
G

Graham Mandeno

Hi Hamid

That's curious! It probably is a form load timing problem, as you say.

What do you get if you say:
MsgBox [Forms]![MainFrom].[Form].Controls(0).Name

Have you tried:
Me.Parent!tvwExample.Object
 
H

Hamid

Hi Graham

When I run MsgBox [Forms]![MainFrom].[Form].Controls(0).Name from
debugger it does normally and displays the control name but using the
Parent format does not solve the issue to refer to it by name and
produces the same error message:

Run-time error '2465' can't find the field 'tvwExample' refered to in
your expression.

Parent also works fine with the index.

Strange!

Thanks, I learned to use Parent. I think it is better approach in
form/subform situations.

Hamid

Graham said:
Hi Hamid

That's curious! It probably is a form load timing problem, as you say.

What do you get if you say:
MsgBox [Forms]![MainFrom].[Form].Controls(0).Name

Have you tried:
Me.Parent!tvwExample.Object

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

zz said:
Hi,
I am able to refer to a Treeview control on the main form using its
control index in the controls collection of the form; but I can not
refer to it by name. i.e. :

In the load event for the subform:
[ok --->] Set objTvwOnMainForm =
[Forms]![MainFrom].[Form].Controls(0).Object

[NOT ok --->]Set objTvwOnMainForm =
[Forms]![MainFrom].[Form].Controls("tvwExample").Object

With the error message: Run-time error '2465' can't find the field
'tvwExample' refered to in your expression. I have double checked the
name but no expected results.

I have no problem using index but I guess there is something like
"subforms load prior to forms" thing that I don't know and also it is
bad idea the code be index dependent rather than name dependent. So any
insight is appreciated.

Hamid
 

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