Hi,
The following code is used to loop through a table and populate a treeview control. (Ms treeview 6.0).
There is a tree index field in the table 1 relates to top level. 2 etc. The code loops through adding 1 to the integer each time clearing the recordset and re opening it with up the maximum level obtained from an recordset generated from an max aggregate query.
When the integer gets to 3 I get runtime 3265 "item cannot be found in the collection corresponding to the requested name or ordinal"
This is an ADO error on the parameter
Anyone have any ideas why this is, the treeview on the form is populated up to level 2.
Regards
Jon
The following code is used to loop through a table and populate a treeview control. (Ms treeview 6.0).
There is a tree index field in the table 1 relates to top level. 2 etc. The code loops through adding 1 to the integer each time clearing the recordset and re opening it with up the maximum level obtained from an recordset generated from an max aggregate query.
When the integer gets to 3 I get runtime 3265 "item cannot be found in the collection corresponding to the requested name or ordinal"
This is an ADO error on the parameter
Anyone have any ideas why this is, the treeview on the form is populated up to level 2.
Regards
Jon
Code:
Private Sub PopulateTheTreeview()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rs1 As ADODB.Recordset
Dim cm As ADODB.Command
Dim intMAXTRI As Integer
Dim intI As Integer
Dim strPK As String
Dim strPARENT As String
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open "QRY_TRI_MAX_AGG", cn
intMAXTRI = rs![intMAXTRI]
rs.Close
Set rs = Nothing
intI = 1
Set cm = New ADODB.Command
With cm
.ActiveConnection = cn
.CommandType = adCmdTable
.CommandText = "QRY_TRV_POP"
.Parameters.Refresh
.Parameters("[PRM1]") = intI
End With
Set rs1 = cm.Execute
Do Until rs1.EOF = True
strPK = StrConv("x" & rs1![PK_TAG], vbLowerCase)
Debug.Print strPK
Me!TRV_AREG.Nodes.Add , , strPK, rs1![EXPR1]
rs1.MoveNext
Loop
rs1.Close
intI = intI + 1
For intI = intI To intMAXTRI
With cm
.CommandType = adCmdTable
.CommandText = "QRY_TRV_POP"
.Parameters.Refresh
.Parameters("[PRM1]") = intI
Set rs1 = .Execute
End With
Do Until rs1.EOF = True
strPK = StrConv("x" & rs1![PK_TAG], vbLowerCase)
strPARENT = StrConv("x" & rs1![int_parent], vbLowerCase)
Me!TRV_AREG.Nodes.Add strPARENT, tvwChild, strPK, rs1![EXPR1]
rs1.MoveNext
Loop
rs1.Close
intI = intI + 1
Next
Set rs1 = Nothing
Set cm = Nothing
Set cn = Nothing
End Sub