Solved

Access 2007 VBA expand treeview from the selected node

Posted on 2014-04-09
4
3,507 Views
Last Modified: 2014-04-15
Hello all,
I've been searching everywhere for this and can't seem to find the answer.  It seems to me that it would be a fairly common question for people using a treeview control, but I can't find anything...

I have a treeview control on an Access 2007 form where I would like the user to be able to select a node in the treeview and then click a command button which will expand every node off of that selected parent.

Any help would greatly be appreciated.
Thanks...
0
Comment
Question by:shannonds
  • 3
4 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39990319
I have not used a treeview in a while, but the best resource I've found for treeviews is:

http://mytreeviewblog.blogspot.com/

The guy who wrote this put together a 6 or 7 part series that covers just about anything you could want to know about a treeview control.

Episode #4 covers expanding and collapsing nodes.

http://mymsaccessblog.blogspot.com/2008/03/my-treeview-project-episode-4-expand.html
0
 

Author Comment

by:shannonds
ID: 39991665
Thanks Dale...  I actually already knew about that blog and have already read the entire series.  I already know how to expand (all) and collapse (all).  My problem is, how to do it from a selected node.

Thanks for trying...
0
 

Accepted Solution

by:
shannonds earned 0 total points
ID: 39992642
In the event someone else is trying to do this, I figured it out...
Here's the code:

Private Sub cmdExpandCurrentBranch_Click()
Dim nodThis As MSComctlLib.Node, intIndex As Integer

On Error Resume Next

    For Each nodThis In Me.xTree.Nodes ' loop through all nodes
        If nodThis.Selected = True Then
            intIndex = nodThis.index
            cmdExpandBranch nodThis 'Expand branch from selected node on
            Exit For
        End If
    Next nodThis
    Me.xTree.SetFocus
    Set Me.xTree.SelectedItem = Me.xTree.Nodes.Item(intIndex)

End Sub

Private Sub cmdExpandBranch(ByVal Node As MSComctlLib.Node)
    Dim i As Integer
   
    For i = Node.index To Node.Next.index - 1
        Me.xTree.Nodes.Item(i).Expanded = True
'        Debug.Print Me.xTree.Nodes.Item(i).Text
    Next i
   
End Sub
0
 

Author Closing Comment

by:shannonds
ID: 40001145
Works like a charm...  Granted I pulled all my hair out trying to figure it out.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

821 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