TreeView Control - Runtime Error 35601 Element Not Found (1 Viewer)

CharlesWhiteman

Registered User.
Local time
Today, 18:14
Joined
Feb 26, 2007
Messages
421
Hi All, I have been following a most clear and informative article on building treeview controls. The article described, and i have successfully replicated, creating a treeview with two levels. My issue relates to adding a second, undocumented in the article, child level. The website is http://mymsaccessblog.blogspot.co.uk/2008/02/my-treeview-project-episode-two.html

My code follows which is erroring at the point in Sub CreateCustNodes:

Code:
    Me.xProductTreeview.Nodes.Add Relationship:=tvwChild, _
        Relative:="Cat=" & CStr(rst!AppID), _
        Text:=rst!PracticeName, Key:="PracticeName=" & CStr(rst!PracticeName)

Full Code:

Code:
Option Compare Database
Private Sub CreateVendorNodes()
  Dim rst As DAO.Recordset ' recordset for category data
  
  ' open the recordset for categories
  Set rst = CurrentDb.TableDefs!TblVendors.OpenRecordset
   
  ' loop through the rows in the recordset
  rst.MoveFirst
  Do Until rst.EOF
    Me.xProductTreeview.Nodes.Add Text:=rst!VendorName, _
      Key:="Cat=" & CStr(rst!VendorID)
    rst.MoveNext
  Loop
  rst.Close
  Set rst = Nothing
End Sub
Private Sub CreateAppNodes()
  Dim rst As DAO.Recordset ' recordset for product data
  
  ' open the recordset for products
  Set rst = CurrentDb.TableDefs!TblApps.OpenRecordset
  
  ' loop through the rows in the recordset
  rst.MoveFirst
  Do Until rst.EOF
    Me.xProductTreeview.Nodes.Add Relationship:=tvwChild, _
        Relative:="Cat=" & CStr(rst!VendorID), _
        Text:=rst!AppTitle, Key:="PracticeName=" & CStr(rst!AppID)
    rst.MoveNext
  Loop
  rst.Close
  Set rst = Nothing
End Sub
Private Sub CreateCustNodes()
  Dim rst As DAO.Recordset ' recordset for product data
  
  ' open the recordset for products
  Set rst = CurrentDb.QueryDefs!QryListLinkedCustToApp.OpenRecordset
  
  ' loop through the rows in the recordset
  rst.MoveFirst
  Do Until rst.EOF
    Me.xProductTreeview.Nodes.Add Relationship:=tvwChild, _
        Relative:="Cat=" & CStr(rst!AppID), _
        Text:=rst!PracticeName, Key:="PracticeName=" & CStr(rst!PracticeName)
    rst.MoveNext
  Loop
  rst.Close
  Set rst = Nothing
End Sub
Private Sub Form_Open(Cancel As Integer)
CreateVendorNodes
CreateAppNodes
CreateCustNodes
End Sub
 

sparks80

Physicist
Local time
Today, 18:14
Joined
Mar 31, 2012
Messages
223
Hi,

I do not have any experience of this but may have spotted the problem.

You currently have the following setup:

Level 1:
Key:="Cat=" & CStr(rst!VendorID)

Level 2:
Key:="PracticeName=" & CStr(rst!AppID)
Relative:="Cat=" & CStr(rst!VendorID)

So the relative of level 2 is the same as the key of level 1.

You need to apply the same logic to level 3 and 2, but in your example you have copied the names and values from the previous level.

You need to change the line that is causing the error to something like this (I think):

Code:
Me.xProductTreeview.Nodes.Add Relationship:=tvwChild, _
        Relative:=PracticeName=" & CStr(rst!AppID), _
        Text:=rst!YourFieldTitle, Key:="NewNodeName=" & CStr(rst!YourFieldValue)
 

Users who are viewing this thread

Top Bottom