Access TreeView "Key is not unique in collection"

Posted on 2010-03-28
Medium Priority
Last Modified: 2012-05-09
I know this is a groaner questions, but does anybody have any troubleshooting tricks for this?

I have checked the code in the .Nodes.Add that sets the Relative: and Key: values until my eyes bleed, and it looks fine.

What's driving me crazy is that the error only occurs when I expand on the parent nodes on the 2nd level, in a particular order.

Thanks for any help

Question by:mlagrange

Accepted Solution

ericathome earned 1000 total points
ID: 28942374
A few possible places to look for answers:

Experts Exchange (similar question and a solution): http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_DB/Q_20889179.html 

     - This solution is good since it provides a script example for eliminating duplicates with the query used to reference the database.

Microsoft (scroll down to "How to Link Nodes in the TreeView Control"): http://support.microsoft.com/kb/162523 

     - This provides some basics on implementing TreeView Controls and potential hazards

These were a couple of basic ones talking about "Key is not unique in collection." If you need additional assistance, it would be good if you could post additional detail. Also, if you can extract the data and run a script to create the tree again, it might strip out the problem node (guessing the tree is too big to debug visually).

Sorry I cannot be more specific without seeing more about your specific issue. Again, provide a bit more detail if you need additional assistance.

Thanks, Eric.
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 28964460
When you add your keys, how do you do it? If I recall correctly, the Key value for a Treeview Node can only be a String, and if you're depending on values like "001" to be different from "01" then sometimes the conversion process will strip out those preceding zeros.

Can you post your code where you're building your tree?

Author Comment

ID: 29444663
LSM - ok, I changed th key for forming a node from
"LevelX=" & CStr(RcdID)
"LevelX=" & Format(RcdID, "00000000")
and the problem stopped happening

Eric - great links

Thanks to you both

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Audit trails are very important in any system to hold people responsible for certain transactions and hold them to take ownership of their actions. This article is dedicated to all novice "Microsoft Access" developers.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

588 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