Link to home
Start Free TrialLog in
Avatar of claracruz
claracruz

asked on

runtime error 35602(key is not unique in collection)

experts, i'm experiencing the above error in the following code whilst trying to initialize my treeview:-

code:-
 Dim cat As Node, cat2 As Node, strLetters As String, adoAttendance2 As ADODB.Recordset, adoAttendance3 As ADODB.Recordset
    Dim I As Integer, strAttendance2 As String, strAttendance3 As String
    Conn
    lvwsLoad
    TreeView1(0).LineStyle = tvwRootLines
    TreeView1(0).Nodes.Clear

    strLetters = "ABCDEFGHIJKLMNOPQRSTUVXYZ"
     
     For I = 1 To 25
        strKey = Mid(strLetters, I, 1)
    Set adoAttendance2 = New ADODB.Recordset
    strAttendance2 = "select * from Players where Players.[Last Name] like '" & strKey & "%' and [Age Category] = 'Adult'"
    adoAttendance2.Open strAttendance2, objConn, adOpenStatic, adLockOptimistic
     
    Set cat2 = TreeView1(0).Nodes.Add(, , strKey, strKey, 1)
         'Start the loop from start
    If adoAttendance2.RecordCount > 0 Then
        While Not adoAttendance2.EOF
            With TreeView1(0).Nodes
        'Put the results together in the treeview
            Set cat = .Add(cat2, tvwChild, strKey & CStr(adoAttendance2.Fields("Last Name")), adoAttendance2.Fields("Last Name") & " " & adoAttendance2.Fields("First Name"), 2)
             adoAttendance2.MoveNext
           End With
           DoEvents
       Wend
    End If
    Next


 'error occurs on this line......
Set cat = .Add(cat2, tvwChild, strKey & CStr(adoAttendance2.Fields("Last Name")), adoAttendance2.Fields("Last Name") & " " & adoAttendance2.Fields("First Name"), 2)

the error occurs when strkey = U%....., i have four names that begin with the letter U, and if i  trap the error withe on error resume next, it returns only one name begining with letter u,........,
i also have 2 names begining with b and that works fine????????? i'm stumped!!
what does this error mean and how do i get rid of it...
   
Avatar of Rejojohny
Rejojohny
Flag of United States of America image

is the lastname same for both the person starting with the letter 'U'
Avatar of claracruz
claracruz

ASKER

yep, all four last names beginning with u are spelt same
if this is the cause of the problem, how do i resolve it.... , i'm not really familiar with the treeview so i am open to suggestions on how else to load data to the treeview.
SOLUTION
Avatar of MYLim
MYLim

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THE EXPERTS HAVE SPOKEN, THANKS GUYS