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("Las t Name") & " " & adoAttendance2.Fields("Fir st 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("Las t Name") & " " & adoAttendance2.Fields("Fir st 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...
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
While Not adoAttendance2.EOF
With TreeView1(0).Nodes
'Put the results together in the treeview
Set cat = .Add(cat2, tvwChild, strKey & CStr(adoAttendance2.Fields
adoAttendance2.MoveNext
End With
DoEvents
Wend
End If
Next
'error occurs on this line......
Set cat = .Add(cat2, tvwChild, strKey & CStr(adoAttendance2.Fields
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...
is the lastname same for both the person starting with the letter 'U'
ASKER
yep, all four last names beginning with u are spelt same
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THE EXPERTS HAVE SPOKEN, THANKS GUYS