Hi there
Im trying to build a subsystem treeview. So I'd like to build a treeview For selected node's children only. I thought I could do that by building hierarchy levels in another field called 'Sublevel' in my treeview table. So macro works like: clear all existing sublevels (not done yet), add 1 for selected node and + 1 for every level below. What I struggle with is looping through children and updating table for each row.
See line 32 (Set NodSelected.Child = NodSelected.Child.Next)- I thought I could do that using child.next but when I run it I get an error message saying that cant edit as it's read only.
Any thoughts or other ideas?
Code just for first couple levels below:
Im trying to build a subsystem treeview. So I'd like to build a treeview For selected node's children only. I thought I could do that by building hierarchy levels in another field called 'Sublevel' in my treeview table. So macro works like: clear all existing sublevels (not done yet), add 1 for selected node and + 1 for every level below. What I struggle with is looping through children and updating table for each row.
See line 32 (Set NodSelected.Child = NodSelected.Child.Next)- I thought I could do that using child.next but when I run it I get an error message saying that cant edit as it's read only.
Any thoughts or other ideas?
Code just for first couple levels below:
Code:
Private Sub BuildSystemTree_Click()
Dim NodSelected As MSComctlLib.Node, aaa As MSComctlLib.Node, bbb As MSComctlLib.Node
Dim a As String, sqlly1 As String, sqlly2 As String, sqlly3 As String
Dim i As Long
Dim PS As ADODB.Recordset
Dim tag As String
DoCmd.SetWarnings False
Set NodSelected = Me.TreeView.SelectedItem
'Use a reference to the Parent node
With NodSelected
getTag tag, NodSelected
sqlly1 = "UPDATE TreeLevels SET Sublevel = '1' WHERE ([Functional location]) = '" & tag & "'"
DoCmd.RunSQL sqlly1
getTag tag, .Child
'Loop through the children
Next
For i = 1 To .Children
getTag tag, .Child
sqlly2 = "UPDATE TreeLevels SET Sublevel = '2' WHERE ([Functional location]) = '" & tag & "'"
DoCmd.RunSQL sqlly2
'Determine if the child has a sub node
If .Child.Children > 0 Then
For j = 1 To .Child.Children
getTag tag, .Child.Child
sqlly2 = "UPDATE TreeLevels SET Sublevel = '3' WHERE ([Functional location]) = '" & tag & "'"
DoCmd.RunSQL sqlly2
.Child.Child = .Child.Child.Next
Next
End If
Set NodSelected.Child = NodSelected.Child.Next
Next
End With
DoCmd.SetWarnings True
End Sub