Here's the code from the knowledge base. The code is for access 97 so you'll have to replace DAO 3.5 by DAO 3.6 . Not sure about the version number, just use the latest one available...
Create and program a TreeView control
Open the Visual Basic Editor, and then perform steps 1 and 2 of the procedure "Add a StatusBar control to a user form" earlier in this article.
In the Available Controls box, select Microsoft TreeView control, version 5.0, and then click OK.
Because you'll be using the Northwind sample database in this procedure, you'll need a reference to DAO 3.5. In the Visual Basic Editor, click References on the Tools menu. In the References dialog box, select Microsoft DAO 3.5 Object Library, and then click OK.
Add a TreeView control to the user form.
Set the user form's Caption property to TreeView.
Set the TreeView control's Name property to tvwODE.
In the Code window, enter the following declarations and procedure:
Option Explicit
Public mdbNWind As Database
Public nodODE As Node
Public rsProducts As Recordset
Private Sub UserForm_Initialize()
' Open the Northwind db.
Set mdbNWind = DBEngine.OpenDatabase("c:\program files\devstudio\vb\nwind.mdb"
' Add a Node object.
Set nodODE = tvwODE.Nodes.Add(, , "r", "Products"
' Open a recordset containing a single field from the Products table.
Set rsProducts = _
mdbNWind.OpenRecordset _
("SELECT Products.ProductName FROM Products;"
Dim intCounter As Integer
' Add nodes displaying product names for four products
For intCounter = 1 To 4
' Add the Node object.
Set nodODE = tvwODE.Nodes.Add(1, tvwChild)
' Set the node Text property.
nodODE.Text = rsProducts!PRODUCTNAME
' Move to the next record.
rsProducts.MoveNext
Next intCounter
End Sub
Click Run Sub/UserForm or press F5.
On the TreeView control, double-click Products to display the nodes that contain product names
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.