Solved

Access 2007 VBA expand treeview from the selected node

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

867 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

16 Experts available now in Live!

Get 1:1 Help Now