Solved

Crating a tree view in Access 2007

Posted on 2010-09-20
5
1,003 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I used this, and it worked.  Thank you!
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

9 Experts available now in Live!

Get 1:1 Help Now