Solved

Access 2007 VBA expand treeview from the selected node

Posted on 2014-04-09
4
3,270 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

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

10 Experts available now in Live!

Get 1:1 Help Now