Crating a tree view in Access 2007

I am using Access 2007 at work and feel that using a tree view to represent a structured hierarchy as a series of nodes is the best and most intuitive way to present my material.  My application comes with two flavors of Tree View: "Microsoft Treeview Control, Version 5.0 (SP2)" and "Microsoft Treeview Control, Version 6.0".  The program does not allow even to use version 5.0, saying I don't have privileges.  I can place version 6.0 into my application, but none of the tutorials I've seen corresponds with the properties and methods avialable on the control.  The most obvious lack is the absence of the "NODES" property, and, hence, the "NODES.ADD" method.  The control looks like it should be the right one, but I can't program it in the most obvious and fundamental ways!  I appreciate your help, as always.
I've included a screenshot for clarity.
Thanks, ~Peter Ferber

Treeview-NoNodesProperty.bmp
PeterFrbAsked:
Who is Participating?
 
Dale FyeConnect With a Mentor Commented:
I use treeviews all the time.  Take a look at the sample database at the bottom of this question.
When you right click the treeview in design mode, and view the events in the Properties dialog, you don't see very many.  But when you go to the VB IDE, select and select the treeview control from the dropdown, then all the events associated with it will display in the other dropdown.
Additionally, you need to make sure you have MSCOMCTL.OCX in your references, this is generally located in the Windows\system32 folder.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The control you're trying to use is NOT certified for use in the Access environment, thus you may find that it does not behave as intended. There are some 3rd party tools that include treeviews (DBI components, for example) that do claim to work, but make sure they're certified for usin in Access 2007.

That said, in general in order to get to the Properties and Methods of an ActiveX in Access, you must declare an Object:

Dim tvw As Treeview

Set tvw = Me.MyTreeviewControl.Object

Access interacts with ActiveX controls very much differently than does other enviroments, which is the reason for the odd referencing method.
0
 
PeterFrbAuthor Commented:
Very interesting comments: thank you for that.  I do note that the Access version of the TreeView object does contain the Nodes property and the Nodes.Add method, but, as anticipated, I get a non-compatible error when attempting to assign an Access TreeView object with the version 6 of the TreeView I inserted (see accompanying screenshot).  

I have 2 questions: 1) Does Access 2007  provide a skimpier selection of controls as its predecessor, as seems to be the case here?  2) Is it possible to instantiate an Access TreeView object from within a form using the Treeview variable?  I believe I've done this in VB6, but it's been a very long while.  

Thanks much,
~Peter Ferber
Treview-CodeError.bmp
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
To be clear, there is no such thing as an "Access Treeview Object". This is an ActiveX control that is built for use with other environments that just happens to work (sometimes) in the Access environment.

The ActiveX controls you see are a listing of ALL controls installed/registered on that specific machine. It has nothing at all to do with the installation of Access. If ProgramA installs ActiveXControl123, then Access will (usually) see a listing for ActiveXControl123. This does NOT mean that you can use that control, or that it will work in Access. It just means the control has been installed on the machine.

As I instructed in my earlier comment, you must set the variable to the .Object:

Dim tvw As Treeview
SEt tvw = Me.MyTreeviewControl.Object

This will give you Intellisense. As Dale said, you would need to move to the VBA Editor in order to see all of the events for that control.

0
 
PeterFrbAuthor Commented:
I used this, and it worked.  Thank you!
0
All Courses

From novice to tech pro — start learning today.