Access TreeView, Invalid Key


I have written an application in access that uses a tree view control. The application works well on my machine and many others. I am running Windows XP and Access 2002. The issue I have is that when I send it to a colleague who also has Windows XP and Access 2002 he gets the following error: 35603, invalid key, the key I am adding is all charactors and numbers. Does anyone have any idea on how to fix this?

Thanks, beccy
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.

what is the code that generates the key?
do you have On Error Resume Next in the code ... that will hide other errors that would stop you before you tried adding and item to a Node.
Have you looked at the references while on his PC to make sure everything is good?

sward4Author Commented:
I have looked at the References which are fine.
I don't have any On error resume next that I don't close afterwards (ie On error resume 0). The code that is generating the node and where the code fails is as follows:
Set Node(i) = TreeView.Nodes.Add("Reg_" + RegionRS!Region, tvwChild, "R" + RepRs!Rep_ID)

have you used a message box or debug.print to find out what the value you are tring to make the key?

I did notice that you are using + instead of & ... by using + what happenms is that if one of the values is Null then your return will be Null also and that would definately be a bad key name :-)

"Reg_" + Null = Null
"Reg_" & Null ="Reg_"   <--- if you are getting multiple items with "Reg_" you will fail also as the item values need to be unique.

Msgbox "Reg+Region= " & "Reg_" + RegionRS!Region
MsgBox "R+RepID= " & R" + RepRs!Rep_ID

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
In addition to Steve's comments:

I've had issues with the Treeview when I didn't explicitly convert my numeric Autonumbers to strings:

"R" + CStr(RepRs!Rep_ID)

Before adding the call to the CStr function, I'd occasionally get the "Invalid Key" error ... but please follow Steve's advice as it is, as always, right on the money.
sward4Author Commented:

Thanks for your ideas, I have whittled the problem down, this is where I am now.

RepRS!RepID is a string Field called "510113". If we add the key "R510113" then the code fails. If we add "R" the code works. Any ideas?

It is doing an implicit conversion and AFAIK there is nothing you can do about it. I always throw an alpha character at the begining of of my node keys to make sure I do get that problem you are having and then I strip it back out when using the Key for something real ... like finding a particular record by the Primary Key number.



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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.