S
Shell
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
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