Hi There
I'm working on the Treeview since a few weeks and this is what I did...
You'll need 3 Tables = 1, Courses (Kurse)
2, Members (Teilnehmer)
4, Actions (Eintrag)
The Difficults on a Treeview are the KeyNodes. They just can be Text - Numbers are not allowed. Thats why you have to change a number to text
The easy way is: "z" & MemberNr or you use strConv()
but the Problem is... Keys are not allowed to be double.
For an easyUse try this in a new Form - drag the ActiveX-TreeView (6.0) into the form and call it "Treeview1"
now get into the design and add the Code to the "FormLoad"
Private Sub Form_Load()
With Me!TreeView1
.Style = tvwTreelinesPlusMinusPictureText
.Indentation = 0
.LineStyle = tvwRootLines
.Nodes.Clear
.Nodes.Add , , "Root", "Root"
.Nodes.Add "Root", tvwChild, "Level1", "Level1"
.Nodes.Add "Root", tvwChild, "Level2", "Level1"
.Nodes.Add "Level1", tvwChild, "Level3", "GrandChild1"
.Nodes.Add "Level3", tvwChild, "Level1a", "GrandChild1"
.Nodes.Add "Level1a", tvwChild, "Levelb", "GrandChild1"
.Nodes.Add "Levelb", tvwChild, , "Data_1"
.Nodes.Add "Levelb", tvwChild, , "Data_2"
.Nodes.Add "Levelb", tvwChild, , "Data_3"
.Nodes.Add "Levelb", tvwChild, , "Data_4"
.Nodes.Add "Level1", tvwChild, "Level4", "GrandChild2"
.Nodes.Add "Level1", tvwChild, "Level5", "GrandChild3"
.Nodes.Add "Level2", tvwChild, "Level6", "GrandChild1"
End With
End Sub
... this is an easy Sample how it works...
the difficult action you'll find down here....
Private Sub Form_Load()
Dim db As DAO.Database
Dim rsKurse, rsTeilnehmer, rsVorgaben, rsEintrag As DAO.Recordset
Dim Node As Object
Set objListImage = Me!FileImages
' Set TreeView control ImageList property
Me!xTree.ImageList = objListImage.Object
' Me!xTree.Sorted = True
Set db = CurrentDb()
'----------------------------------------------------------------------
' Level 1 '
'----------------------------------------------------------------------
Dim strSQLA As String
strSQLA = "SELECT * FROM tblKurse "
strSQLA = strSQLA & "ORDER BY [tblKurse].[KursBezeichnung]; "
Set rsKurse = db.OpenRecordset(strSQLA, dbOpenDynaset)
If rsKurse.RecordCount > 0 Then
Do Until rsKurse.EOF
Lev1 = "kurs" & rsKurse!KursNr
Set Node = Me!xTree.Nodes.Add(, , Lev1, CStr(rsKurse!KursBezeichnung), "Kurs"

' Node.ExpandedImage = "p2"
rsKurse.MoveNext
'----------------------------------------------------------------------
' Level 2 '
'----------------------------------------------------------------------
Dim strSQL1 As String
strSQL1 = "SELECT * FROM tblTeilnehmer "
strSQL1 = strSQL1 & "WHERE ((([tblTeilnehmer].[TlnAktiv])=Yes)) "
strSQL1 = strSQL1 & " and [KursNr]=" & Mid(Lev1, 5)
strSQL1 = strSQL1 & " ORDER BY [tblTeilnehmer].[TlnName]; "
Set rsTeilnehmer = db.OpenRecordset(strSQL1, dbOpenDynaset)
If rsTeilnehmer.RecordCount > 0 Then
Do Until rsTeilnehmer.EOF
lev2 = Lev1 & rsTeilnehmer!TlnNr
Set Node2 = Me!xTree.Nodes.Add(Lev1, tvwChild, _
lev2, CStr(rsTeilnehmer!TeilnehmerName), "tln"

' Node2.ExpandedImage = "tlnof"
rsTeilnehmer.MoveNext
'----------------------------------------------------------------------
' Level 3 '
'----------------------------------------------------------------------
Dim strSQL2 As String
strSQL2 = "SELECT * FROM tblVorgaben "
'strSQL2 = strSQL2 & "WHERE [TlnNr]=" & Mid(Lev2, 9)
Set rsVorgaben = db.OpenRecordset(strSQL2, dbOpenDynaset)
If rsVorgaben.RecordCount > 0 Then
Do Until rsVorgaben.EOF
Lev3 = lev2 & "z" & rsVorgaben!VorgabeNr
vorgabe = rsVorgaben!VorgabeBezeichnungLong
Set Node3 = Me!xTree.Nodes.Add(lev2, tvwChild, Lev3, vorgabe, "info"

'Node3.ExpandedImage = "eintragof"
rsVorgaben.MoveNext
'----------------------------------------------------------------------
' Level 4 '
'----------------------------------------------------------------------
Dim strSQL3 As String
strSQL3 = "SELECT * FROM tblEintrag "
strSQL3 = strSQL3 & "WHERE [VorgabeNr]=" & Mid(Lev3, 14)
strSQL3 = strSQL3 & " and [TlnNr]=" & Mid(lev2, 9, 4)
strSQL3 = strSQL3 & " ORDER BY tblEintrag.Datum DESC; "
Set rsEintrag = db.OpenRecordset(strSQL3, dbOpenDynaset)
If rsEintrag.RecordCount > 0 Then
Do Until rsEintrag.EOF
Lev4 = "e" & rsEintrag!eNr
' zahler = Me!xTree.Nodes.Count
' zahler = rsEintrag.RecordCount - 1
' ezahl = rsEintrag.RecordCount
Set Node4 = Me!xTree.Nodes.Add(Lev3, tvwChild, Lev4, _
rsEintrag!Datum & " - " & rsEintrag!EintragGrund, "zeit"

'Node4.ExpandedImage = "tlnof"
rsEintrag.MoveNext
Loop
End If
rsEintrag.Close
' End of Level 4
Loop
End If
rsVorgaben.Close
' End of Level 3
Loop
End If
rsTeilnehmer.Close
' End of Level 2
Loop
End If
rsKurse.Close
db.Close
' End of Level 1
End Sub
there is code missing to connect to the data after click a Node... just contact me to get a sample db...
cu
