Solved

Crating a tree view in Access 2007

Posted on 2010-09-20
5
1,005 Views
Last Modified: 2013-12-20
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
0
Comment
Question by:PeterFrb
  • 2
  • 2
5 Comments
 
LVL 84
ID: 33720921
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
 

Author Comment

by:PeterFrb
ID: 33721315
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
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 33758939
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
 
LVL 84
ID: 33760005
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
 

Author Closing Comment

by:PeterFrb
ID: 33774413
I used this, and it worked.  Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now