[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1111
  • Last Modified:

Access TreeView, Invalid Key

Hi,

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
0
sward4
Asked:
sward4
  • 3
  • 2
1 Solution
 
stevbeCommented:
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?

Steve
0
 
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)

Thanks
0
 
stevbeCommented:
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

Steve
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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.
0
 
sward4Author Commented:
Hi,

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?

Thks.
0
 
stevbeCommented:
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.

Steve

0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now