views:

41

answers:

1

I have a database(3 tables). I want to build treeView.

I don't know how to create recordset and how to retrieve record from it.

A: 

I have created a form and added treeview activex control and I load following Filltree function on form_load event.

each tree(table) data have parentid. If parentid=0 then its is a node.

Sub FillTree()
    Dim TNode As node
    Dim oRs As DAO.Recordset

    Set oRs = CurrentDb.OpenRecordset("SELECT Query FROM THREE TABLES", dbReadOnly, dbSeeChanges)
    oRs.MoveFirst
    While Not oRs.EOF
        If oRs.Fields("ParentID") > 0 Then
            Me.TreeView0.Nodes.Add "key" & oRs.Fields("ParentID"), tvwChild, "key" & oRs.Fields("id"), oRs.Fields("TREEDATA")
        Else
            Me.TreeView0.Nodes.Add , , "key" & oRs.Fields("id") & "", oRs.Fields("TREEDATA")
        End If
        oRs.MoveNext
    Wend


End Sub
THEn