Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access 2007 VBA expand treeview from the selected node

Posted on 2014-04-09
4
Medium Priority
?
3,943 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

636 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