Click to See Complete Forum and Search --> : Please help - Error 457 - Index already associated with this item.


John Reynolds
July 4th, 2001, 10:33 AM
Simple form used to input 2 strings (key & value), to be stored in Dictionary (dictLocations)which is instantiated in Module1. Works fine until user clicks yes in message box, then get Error 457 (duplicate key)???

Thanks for anyone's help!


private Sub cmdOK_Click()
Dim key as string, val as string
dictLocations.Add tbLocNo, tbLocDesc
If MsgBox("Add Another Location?", vbYesNo) = vbYes then

me.Hide
tbLocNo = ""
tbLocDesc = ""
me.Show

else

me.Hide
End If
Unload.me
End Sub

michi
July 4th, 2001, 12:25 PM
It sames that the key (tbLocNo) of dictLocations is not unique. I don't know how you get the value of tbLocNo before calling dictLocation.Add, but if it is possible that tbLocNo is duplicate, try to add a suffix to make it unique. For example:

dictLocation.Add tbLocNo & CStr(intCounter), tbLocDesc



Regards,

Michi
MCSE, MCDBA

John Reynolds
July 4th, 2001, 07:06 PM
The FIRST key value is changing anytime tbLocNo changes. I don't understand why, but when the user enters a SECOND key value in the textbox, the FIRST key entry in the dict changes to that value. Thus, when the Add method is called, the key is already in the dictionary. (?)

Thanks for your help.
John R.