tammyl
11-17-2010, 01:46 AM
Hi,
I'm trying to create a treeview form. I've setup the form & now creating the Parent & Child Nodes.
I have three tables.
tAuthors - AuthorID, Firstname, lastname
tBooks - BookID, title, etc
tBookAuthors - AuthorID, BookID
tBookAuthors has the link relationship between tAuthors & tBooks so that i can have many authors for one book.
How do i display text from tAuthors & tBooks in my treeview.
I'm using tBookAuthors ad the main recordset because that's where the relationship is??
Following is my vba code i'm using but i'm getting an error mesage.
Run-time error '3265' Item not found in collection.
I know it's got to do with how i'm referencing the 'text' part of the code.
Private Sub CreateParentNodes()
Dim rst As DAO.Recordset ' recordset for category data
' open the recordset for categories
Set rst = CurrentDb.TableDefs!tBookAuthors.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
Me.TreeView1.Nodes.Add Text:=rst![tAuthors].[AuthorLastName], _
Key:="Cat=" & CStr(rst![tBookAuthors].[AuthorID])
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Private Sub CreateChildNodes()
Dim rst As DAO.Recordset ' recordset for product data
' open the recordset for products
Set rst = CurrentDb.TableDefs!tBookAuthors.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
Me.TreeView1.Nodes.Add Relationship:=tvwChild, _
Relative:="Cat=" & CStr(rst![tBookAuthors].[AuthorID]), _
Text:=rst![tBooks].[Title], Key:="Prod=" & CStr(rst![tBookAuthors].[BookID])
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Any help much appreciated. :bow:
Cheers
tammyl
I'm trying to create a treeview form. I've setup the form & now creating the Parent & Child Nodes.
I have three tables.
tAuthors - AuthorID, Firstname, lastname
tBooks - BookID, title, etc
tBookAuthors - AuthorID, BookID
tBookAuthors has the link relationship between tAuthors & tBooks so that i can have many authors for one book.
How do i display text from tAuthors & tBooks in my treeview.
I'm using tBookAuthors ad the main recordset because that's where the relationship is??
Following is my vba code i'm using but i'm getting an error mesage.
Run-time error '3265' Item not found in collection.
I know it's got to do with how i'm referencing the 'text' part of the code.
Private Sub CreateParentNodes()
Dim rst As DAO.Recordset ' recordset for category data
' open the recordset for categories
Set rst = CurrentDb.TableDefs!tBookAuthors.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
Me.TreeView1.Nodes.Add Text:=rst![tAuthors].[AuthorLastName], _
Key:="Cat=" & CStr(rst![tBookAuthors].[AuthorID])
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Private Sub CreateChildNodes()
Dim rst As DAO.Recordset ' recordset for product data
' open the recordset for products
Set rst = CurrentDb.TableDefs!tBookAuthors.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
Me.TreeView1.Nodes.Add Relationship:=tvwChild, _
Relative:="Cat=" & CStr(rst![tBookAuthors].[AuthorID]), _
Text:=rst![tBooks].[Title], Key:="Prod=" & CStr(rst![tBookAuthors].[BookID])
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Any help much appreciated. :bow:
Cheers
tammyl