Weird, simple (?) Treeview question with Access

G

Guest

I have used treeviews in the past, both with Excel and Access, but I'm in the
relearning phase for using it with Access. Here's a very strange basic
problem I don't recall having before, so it really has me perplexed.

If I want to manipulate a treeview in a module or class module, I have to
declare the variable as a TreeView in order to get the critical properties
(like Nodes). But when I try to assign it to the actual treeview on a form,
VBA doesn't return the treeview as a TreeView type, but rather as a
CustomControl type, causing a type clash at runtime. But declaring the
variable as CustomControl doesn't let me use the TreeView properties from the
editor. Even if I try manipulating the TreeView in the actual treeview event
handler code, it recognizes the treeview by its name, but there are no
treeview-specific properties/methods available from the editor (although the
events seem to be there).

What I found is that if I go ahead and type out the Nodes (for example)
property, it actually binds at runtime if I use generic types (or just
pretend nothing's wrong in the event handler code). But this seems like a
bizarre misfit. In addition, all the resources I used to use on MSDN for
learning the treeview object seem gone (actually, the entire site seems shot,
or else it's just down for now), so flying blind without even the clues from
the editor is hard.

Am I doing something wrong here? I feel like I'm taking crazy pills... But
I've tried all the obvious stuff... I think... (comctrls is referenced, e.g.).

Thanks,
BnB
 
G

Guest

BnB,

The treeview control is not part of the standard controls (i.e.: it is a
custom control). If you are seeing late binding (i.e.: at runtime) as
opposed to early binding, which makes property/method lists available during
coding, this is symptomatic of a missing project "reference."

Add a reference to the treeview control by right-clicking in the form
"Toolbox - Controls" and selecting "Additional Controls." Do NOT use VBA
task menu's "Tools - References." Reserve VBA references for non-control
objects (e.g.: ADO, DAO, SQLDMO, etc.). Once you have included the proper
reference (in the Form Toolbox - Controls), you should be able to see
properties/methods and recognize the treeview control type in your forms.

Joseph
 
G

Guest

Thanks Joseph. Actually, I have already done what you said. In fact, if I
declare something as a treeview, then I get the edit-time behavior. The
problem is that I can't reference the treeview as a Treeview type object. If
I have a treeview named MyTreeview on a form called MyForm, then
MyForm.MyTreeview doesn't return a Treeview type, but a CustomControl type.
If I declare a variable as Treeview type, in order to get the properties etc.
recognized, and then assign it's a type clash. In other words, the following
doesn't work:

dim MyVariable as Treeview

set MyVariable=MyForm.MyTreeview

So I have to declare the variable to which I'm assigning the treeview as
type CustomControl instead, which then doesn't recognize the treeview
properties etc.

dim MyVariable as CustomControl

set MyVariable=MyForm.MyTreeview

I've found no way to convert (even though, ironically, theoretically objects
are the "easiest" data to convert since it's just a reference address).

This is the problem I was trying to address: the fact that somehow the form
can't return a non-built-in control type with its actual control type.

Bryon
 
G

Guest

Yes, that's exactly what I've tried. I can pass the Treeview around, but
after creating a Treeview using the graphical controls (not
programmatically), there's no way to reference the actual control with a
Treeview type. Let's say I call MySub and pass the Treeview named MyTreeview
on MyForm. I can use the following possibilities:

MySub(MyForm!MyTreeview)
MySub(MyForm.MyTreeview)
MySub(MyForm.Controls("MyTreeview")

But I'll get a type clash because the parameter says to expect type
"Treeview", and that's not the type that I get from the reference. If I do
TypeName(MyForm.MyTreeview), for example, while debugging, I get the type
"CustomControl", not the type "Treeview".

That's the essence of the problem.

Bryon
 
G

Guest

Sir,

What version of Excel/VBA are you running? I am using Office '03 Excel and
VB 6.3 in VBA. Under this environment (with XP OS), I do not see the
problems which you are describing. Once I add the control to the tollbox and
draw the control on my form, I have full programmatic access to
methods/properties.

Your problem seems peculiar to me (as I'm sure it does to you) because I
have not seen an example of early binding that does not work in run-time.

Are you creating the control programmatically, or are you drawing it on a
form and referencing that form object? Are you / Is there a purpose to -
creating a local copy of the treeview object (as in your sample code)? Have
you tried writing a subroutine with the treeview control as a parameter?

MySub MyTreeview

Subroutine MySub (MyVariable as Treeview)

I have found that this is an effective way to force VB to recognize other
things (e.g.: data structures) properly and correctly. You might give that a
try (even if it sounds silly, trust me - it has worked for me in the past).

Joseph
 

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