smttools
Jun 2nd, 2005, 08:52 AM
Hi, I'm trying to create a form using the treeview control . I know how to polpulate a simple tree view but this one is too complicated for me to work out.
My data is arranged like this:
CategoryID|v_categories_name_1|v_categories_name_2|v_categories_name_3|v_categories_name_4|v_categor ies_name_5
126|Hardware|Abrasive Products|Sanding Rolls|Aluminium Oxide|100mm X 50m
127|Hardware|Abrasive Products|Sanding Rolls|Aluminium Oxide|115mm X 10m
If someone knows of an example to download then please help, Cheers for looking
This is the code I have so far:
Sub Buildbranch(Optional varParentID As Variant)
On Error Resume Next
Dim oTree As TreeView, nodCurrent As Node
Dim Db As DAO.Database
Dim rstCat1 As DAO.Recordset
Dim rstSub As DAO.Recordset
Dim strText As String
Dim strKey As String
Dim intNum As Integer
Set oTree = Me!TreeCtl.Object
strText = "Categories"
strKey = "rootNode"
Set nodCurrent = oTree.Nodes.Add(, , strKey, strText)
Set Db = CurrentDb()
Set rstCat1 = Db.OpenRecordset("SELECT DISTINCT tblCat.v_categories_name_1 FROM tblCat;", dbOpenDynaset)
rstCat1.MoveFirst
Do Until rstCat1.EOF
strText = rstCat1!v_categories_name_1
strKey = "A_" & rstCat1!CategoryID
intNum = rstCat1!CategoryID
Set nodCurrent = oTree.Nodes.Add("rootNode", tvwChild, strKey, strText)
'Loop thru all other categories
rstCat1.MoveNext
Loop
End Sub
My data is arranged like this:
CategoryID|v_categories_name_1|v_categories_name_2|v_categories_name_3|v_categories_name_4|v_categor ies_name_5
126|Hardware|Abrasive Products|Sanding Rolls|Aluminium Oxide|100mm X 50m
127|Hardware|Abrasive Products|Sanding Rolls|Aluminium Oxide|115mm X 10m
If someone knows of an example to download then please help, Cheers for looking
This is the code I have so far:
Sub Buildbranch(Optional varParentID As Variant)
On Error Resume Next
Dim oTree As TreeView, nodCurrent As Node
Dim Db As DAO.Database
Dim rstCat1 As DAO.Recordset
Dim rstSub As DAO.Recordset
Dim strText As String
Dim strKey As String
Dim intNum As Integer
Set oTree = Me!TreeCtl.Object
strText = "Categories"
strKey = "rootNode"
Set nodCurrent = oTree.Nodes.Add(, , strKey, strText)
Set Db = CurrentDb()
Set rstCat1 = Db.OpenRecordset("SELECT DISTINCT tblCat.v_categories_name_1 FROM tblCat;", dbOpenDynaset)
rstCat1.MoveFirst
Do Until rstCat1.EOF
strText = rstCat1!v_categories_name_1
strKey = "A_" & rstCat1!CategoryID
intNum = rstCat1!CategoryID
Set nodCurrent = oTree.Nodes.Add("rootNode", tvwChild, strKey, strText)
'Loop thru all other categories
rstCat1.MoveNext
Loop
End Sub