inunghwrote:
Thanks millions,
Can you please help me the code to expand the tree view on form open?
Thanks again,
Not sure what you want here but here is a treeview fill that I posted for
someone else. Hope it helps. You can read through the code and place your
tables and queries as needed and field names... etc
THis is essentially a form with just a TreeView control placed on it.
Option Compare Database
Option Explicit
Public WithEvents TrVw As TreeView
Private Sub Form_Load()
Set TrVw = Me.TreeView0.Object
PopulateTree1
End Sub
Private Sub PopulateTree1()
'this will popluate the names
Dim EmplID As Long
Dim rst As New ADODB.Recordset
Dim nod As Node
Dim nod2 As Node
Set nod = TrVw.Nodes.Add(, , "TrSch", "Training")
nod.EnsureVisible
nod.Expanded = True
Set nod2 = TrVw.Nodes.Add(nod.Key, tvwChild, CStr("T1"), "Title" & "
" & "Taken" & " " & "Due")
'This will only give you employees that actually have a training record
With rst
.Open "SELECT DISTINCTROW Employees.EmployeeID, Employees.LastName,
Employees.FirstName " & _
"FROM Employees INNER JOIN [employee training] ON Employees.EmployeeID =
[employee training].Employee_ID " & _
"ORDER BY Employees.LastName;", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
Do Until .EOF
EmplID = !EmployeeID
With TrVw
'the node is added as Relative, Relation,Key,Text,image (not
using here)
Set nod2 = .Nodes.Add(nod.Key, tvwChild, CStr("E" & rst!
EmployeeID), rst!LastName & ", " & rst!FirstName)
PopulateTree2 EmplID, CStr("E" & rst!EmployeeID)
nod2.Expanded = True
End With
.MoveNext
Loop
End With
End Sub
Private Sub PopulateTree2(EmployeeID As Long, NodKey As String)
'this will populate the training
Dim rst As New ADODB.Recordset
With rst
.Open "SELECT [employee training].Employee_ID, [employee training]..
Trng_ID, [employee training].Taken, [employee training].Due, Training.Title "
& _
"FROM [employee training] INNER JOIN Training ON [employee training].
Trng_ID = Training.Training_ID " & _
"WHERE ((([employee training].Employee_ID)=" & EmployeeID & "));",
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do Until .EOF
With TrVw
.Nodes.Add NodKey, tvwChild, "", rst!Title& " " &
(Nz(rst!Taken, "-")) & " " & (Nz(rst!Due, "-"))
'no key need because there are no relationships below this
level to have a relation with
End With
.MoveNext
Loop
.Close
End With
End Sub
Code end ******************************