Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeView control

Status
Not open for further replies.

imendi

Programmer
Oct 14, 2002
33
ES
Hello,

I have a form where I want to put a treeview control where I can select a database.

How could I do that?

thanks,

im
 
Hello imendi,

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

Hope this helps

Kind regards
Borg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top