Private Sub Command1_Click()
Dim conn2 As ADODB.Connection
Dim dept1, equp1, one1, two1, three1, four1, five1, d1
Set conn2 = New ADODB.Connection
conn2.Provider = "microsoft.jet.oledb.4.0"
'conn2.ConnectionString="DSN="Database
conn2.Open "Database"
TreeView1.Nodes.Clear
dept1 = ""
equp1 = ""
d1 = 0
rec2open
rec2.ActiveConnection = conn2
rec2.Open "SELECT* from my Table;"
If rec2.EOF = False And rec2.BOF = False Then
Do While rec2.EOF = False
If dept1 <> rec2.Fields(0) Then
d1 = d1 + 1
TreeView1.Nodes.Add , , "*" & CStr(rec2.Fields(0)) & "*", rec2.Fields(0)
If UCase(rec2.Fields(2)) = "ONE" Then
TreeView1.Nodes.Add "*" & rec2.Fields(0) & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 3) & " " & rec2.Fields(4)
one1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "TWO" Then
TreeView1.Nodes.Add "*" & one1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 5) & " " & rec2.Fields(4)
two1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "THREE" Then
TreeView1.Nodes.Add "*" & two1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 7) & " " & rec2.Fields(4)
three1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "FOUR" Then
TreeView1.Nodes.Add "*" & three1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 9) & " " & rec2.Fields(4)
four1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "FIVE" Then
TreeView1.Nodes.Add "*" & four1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 11) & " " & rec2.Fields(4)
five1 = rec2.Fields(3)
End If
dept1 = rec2.Fields(0)
Else
If UCase(rec2.Fields(2)) = "ONE" Then
TreeView1.Nodes.Add "*" & rec2.Fields(0) & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 3) & " " & rec2.Fields(4)
one1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "TWO" Then
TreeView1.Nodes.Add "*" & one1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 5) & " " & rec2.Fields(4)
two1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "THREE" Then
TreeView1.Nodes.Add "*" & two1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 7) & " " & rec2.Fields(4)
three1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "FOUR" Then
TreeView1.Nodes.Add "*" & three1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 9) & " " & rec2.Fields(4)
four1 = rec2.Fields(3)
ElseIf UCase(rec2.Fields(2)) = "FIVE" Then
TreeView1.Nodes.Add "*" & four1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 11) & " " & rec2.Fields(4)
five1 = rec2.Fields(3)
End If
dept1 = rec2.Fields(0)
End If
rec2.MoveNext
Loop
End If
End Sub