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

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
Stephen NobleSr. Epic Applications AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
I just went through the docs briefly and it looks like you want the ActivateNode method, not ScrollToView.

Jim.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Stephen NobleSr. Epic Applications AnalystAuthor 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 (Microsoft MVP/ EE MVE)President / OwnerCommented:
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 ExpertCommented:
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 (Microsoft MVP/ EE MVE)President / OwnerCommented:
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 ExpertCommented:
:-) Duh, I should've known that! Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.