I have a simple form with an ActiveX TreeView Control (TreeView0) and a Command Button (Command1). I also have a table (Table1) with 2 fields (Id & Parent).
The code below should simply populate the treeview control. It is tripping up on the 'Set nodX = objTree.Nodes.Add(Parent, tvwChild, MyRS!Id)'. It comes up with 'Run-time error 35601: Element not found'.
I just can't seem to get the add node on this tree view to work.
The code below should simply populate the treeview control. It is tripping up on the 'Set nodX = objTree.Nodes.Add(Parent, tvwChild, MyRS!Id)'. It comes up with 'Run-time error 35601: Element not found'.
I just can't seem to get the add node on this tree view to work.
Code:
Option Compare Database
Private Sub Command1_Click()
Dim nodX As Node
Dim objTree As TreeView
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim MyRSChild As DAO.Recordset
Dim strSQL As String
Dim Parent As String
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset("Table1", dbOpenDynaset)
Set objTree = Me!TreeView0.Object
objTree.Nodes.Add , , , "Hierarchy"
Do While Not MyRS.EOF
If IsNull(MyRS!Parent) Then Parent = "Hierarchy" Else Parent = MyRS!Parent
Set nodX = objTree.Nodes.Add(Parent, tvwChild, MyRS!Id)
nodX.EnsureVisible
MyRS.MoveNext
Loop
End Sub