Question : Adding Child Nodes to tree view in VBA

I am trying to populate a tree view control in Microsoft Access dynamically with a hierarchial data set.  I populate the tree view with the first level nodes and put a "dummy" node beneath each of them to ensure there is a plus sign.  I'm trying to run the following code in the expand event and getting an error on the "set nod = ..." line saying that the "Object doesn't support this property or method."  Anyone know what I'm doing wrong?

Private Sub tvwRegs_Expand(ByVal Node As Object)

Dim strSQL As String
Dim rst As New ADODB.Recordset
Dim intID As Integer
Dim nod As Node

intID = Left(Node.Key, Len(Node.Key) - 1)

'Clear any existing nodes
While Node.Children <> 0
    Me.tvwRegs.Nodes.Remove (Me.tvwRegs.Nodes(Node.Index).Child.Index)
Wend

strSQL = "select RegID, Title from tblRegs where ParentID = " & intID & " order by 2"
rst.Open strSQL, CurrentProject.Connection, adOpenForwardOnly

Do Until rst.EOF
    'Create child node
    Set nod = Me.tvwRegs.Nodes(Node.Index).Nodes.Add(rst!RegID & "|", tvwChild, rst!RegID & "|", rst!Title)

    rst.MoveNext
Loop

rst.Close
Set rst = Nothing
End Sub

Answer : Adding Child Nodes to tree view in VBA

It shows you the syntax of how to add a new node

TreeView1.Nodes.Add Relative, Relationship, Key, Text, Image, SelectedImage

so your code would be

Treeview1.Nodes.Add(Node , tvwchild, "yourKey" , "YourText")

see http://www.developerfusion.com/article/77/treeview-control/2/
Random Solutions  
 
programming4us programming4us