Key is not unique in collection

G

Guest

I made the following code:
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim i, j, k, l, m, n As Integer
Dim STemp, STemp1, STemp2, STemp3, STemp4, STmep5 As String
Dim MsNode As Node
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Me.twvStruct.LineStyle = tvwTreeLines
j = 0
STemp = "Select * From BOM "
Rs.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Rs.MoveFirst
For i = 1 To Rs.RecordCount
If Rs("Status1") = "FG" Then
j = j + 1
Set MsNode = Me.twvStruct.Nodes.Add(, , Rs("ParentPN"),
Rs("ParentPN"))
twvStruct.Nodes(j).Expanded = True
If Rs("Status2") = "WIP" Then
STemp1 = Rs("ParentPN")
STemp2 = Rs("ChildPN")
For k = 1 To Rs.RecordCount
If Rs("ParentPN") = STemp2 Then
l = j + 1
Set MsNode = Me.twvStruct.Nodes.Add(STemp1, tvwChild,
Rs("ChildPN"), Rs("ChildPN"))
twvStruct.Nodes(l).Expanded = True
If Rs("Status2") = "WIP" Then
STemp3 = Rs("ParentPN")
STemp4 = Rs("ChildPN")
For m = 1 To Rs.RecordCount
If Rs("ParentPN ") = STemp4 Then
n = l + 1
Set MsNode = Me.twvStruct.Nodes.Add(STemp3,
tvwChild, Rs("ChildPN"), Rs("ChildPN"))
twvStruct.Nodes(n).Expanded = True
Else
Rs.MoveNext
End If
Next m
End If
Else
Rs.MoveNext
End If
Next k
End If
Else
Rs.MoveNext
End If
Next i
Set Rs = Nothing
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load


End Sub

But it can not work. It shows "Key is not unique in collection". Would you
please help me check where the problem it is?

Shell
 
B

Baz

I doubt that anyone is going to be interested in debugging that for you, you
might at least have indicated which line the error occurs on. However, I
would point out that your variable declarations are unlikely to be what you
intended. For example, "Dim i, j, k, l, m, n As Integer" will declare i, j,
k, l and m as variants, only n will be an integer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top