jkp-ads.com treeview - How to select node in treeview with Key value

Stephen Noble
Stephen Noble used Ask the Experts™
on
II have replaced my Active X treeview with the below custom solution in my MS Access 2013 db.

Does anyone know how I can pass a Key value and have the treeview select this node? I have read the documentation and feel I would use the sub "ScrollToView" but unable to implement it yet.

 https://www.jkp-ads.com/articles/treeview.asp
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
I just went through the docs briefly and it looks like you want the ActivateNode method, not ScrollToView.

Jim.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
I just downloaded the example and class modules, and I can't find an Activate method.   I couldn't find it in the Excel version either.  A note to the author might be the fastest answer.

Jim.
President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012
Commented:
Try adding this to the class:

Public Sub ActivateNodeByKey(sKey As String)
    Dim cNode As clsNode
    For Each cNode In mcolNodes
        If cNode.Key = sKey Then
            Set ActiveNode = cNode
            Exit Sub
        End If
    Next
End Sub
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Stephen NobleSr. Epic Applications Analyst

Author

Commented:
Jim... I was getting errors with that but it sounded like a sound approach.

With a little luck, I modified it to the below and this worked! Ahhh now I can relax again.

Public Sub ActivateNodeByKey(sKey As String)

Dim cNode As clsNode
For Each cNode In mctree.Nodes
    If cNode.key = sKey Then
        Set mctree.ActiveNode = cNode
        Exit Sub
    End If
Next

As a note... to get a child node (if set to ActiveNode) to expand (if not already), i had to ensure the focus was set on the subform holding the treeview.

End Sub
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
Thanks for posting that.

Note that I've contacted the author about the missing method, so stay tuned for updates.  It may be that just the wrong download is being publish (ie. old build?).

That code BTW I found in the comments section of their web site.   So my guess is that it was added at some point to the lib and we're just getting the wrong download.

Jim.
Jan Karel PieterseExcel and VBA Expert

Commented:
As one of the authors (and owner of the jkp-ads site) I can tell you the SelectNodeByKey is NOT included in the download. We have however recently updated the MSAccess download so it matches the Excel version (026).
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
It was passed along that all you need is:

Set mcTree.ActiveNode = mcTree.Nodes("myKey")

 Which is why ActivateNode was removed.

Jim.
Jan Karel PieterseExcel and VBA Expert

Commented:
:-) Duh, I should've known that! Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial