gibbo1715
10-22-2005, 09:40 AM
All
Im trying to populate a treeview on a userform from an access table using the code below
I want the parent to be the table(Recordset) name and the child to be the contents of the column FieldName2 but Im getting nowhere
My code works and I ve figured out how to populate it with the table column titles but what i want to be able to do is list the records in the columns
Anyone got any ideas as I cant find the answer to this anywhere
Thanks
Gibbo
Sub Populate_Treeview()
Dim cnt As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDb As String, strSQL As String
Dim xlCalc As XlCalculation
Dim j As Long, x As Long
'SET YOUR VARIABLES HERE:
'Path to the database and SQL-statement to execute
strDb = "C:\Gibbos.mdb"
strSQL = "SELECT tbl_TEST.* From tbl_Test"
'In order to increase performance
With Application
xlCalc = .Calculation
.EnableEvents = False
.ScreenUpdating = False
End With
'Establish and ADO connection
Set cnt = New ADODB.Connection
'Create the connection string
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDb & ";"
'Retrieve the recordset and count fields & records
rst.Open strSQL, cnt
'Add the items to the listbox
With UserForm1
UserForm1.TreeView1.Nodes.Add , , "Table", "Table"
'Child
For x = 0 To rst.Fields.Count - 1
UserForm1.TreeView1.Nodes.Add "Table", 4, , rst.Fields(x).Name
Next x
End With
AddCounter
'Close the recordset, connection and release objects from memory
With rst
.Close
.ActiveConnection = Nothing
End With
cnt.Close
Set rst = Nothing
Set cnt = Nothing
'Restore the settings
With Application
.Calculation = xlCalc
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Im trying to populate a treeview on a userform from an access table using the code below
I want the parent to be the table(Recordset) name and the child to be the contents of the column FieldName2 but Im getting nowhere
My code works and I ve figured out how to populate it with the table column titles but what i want to be able to do is list the records in the columns
Anyone got any ideas as I cant find the answer to this anywhere
Thanks
Gibbo
Sub Populate_Treeview()
Dim cnt As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDb As String, strSQL As String
Dim xlCalc As XlCalculation
Dim j As Long, x As Long
'SET YOUR VARIABLES HERE:
'Path to the database and SQL-statement to execute
strDb = "C:\Gibbos.mdb"
strSQL = "SELECT tbl_TEST.* From tbl_Test"
'In order to increase performance
With Application
xlCalc = .Calculation
.EnableEvents = False
.ScreenUpdating = False
End With
'Establish and ADO connection
Set cnt = New ADODB.Connection
'Create the connection string
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDb & ";"
'Retrieve the recordset and count fields & records
rst.Open strSQL, cnt
'Add the items to the listbox
With UserForm1
UserForm1.TreeView1.Nodes.Add , , "Table", "Table"
'Child
For x = 0 To rst.Fields.Count - 1
UserForm1.TreeView1.Nodes.Add "Table", 4, , rst.Fields(x).Name
Next x
End With
AddCounter
'Close the recordset, connection and release objects from memory
With rst
.Close
.ActiveConnection = Nothing
End With
cnt.Close
Set rst = Nothing
Set cnt = Nothing
'Restore the settings
With Application
.Calculation = xlCalc
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub