?
Solved

Access 2007 VBA expand treeview from the selected node

Posted on 2014-04-09
4
Medium Priority
?
3,804 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 48

Expert Comment

by:Dale Fye
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 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