We help IT Professionals succeed at work.

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

Stephen Noble
on
308 Views
Last Modified: 2019-01-29
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

Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

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
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

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
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
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
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

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
CERTIFIED 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
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

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
CERTIFIED EXPERT

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.