Hello
I have used below code for filling tree view with 2 levels. This tree view shows books for each Author, now I like to add level 3 (transmittal no) for each book for example author1 has 2 books (book1, book2) and then for book1 we have 4 transmittal no (tt -003, tt-1000,tt-4000,tt-5000) and for book2 we have 1 transmittal no (tt-0009)
My tables for 2 levels are:
tblAuthors (AuthorID (pk), AuthorFirstName, AuthorLastName)
tblBooks (BookID (pk),title)
tblBookAuthor (AuthorID, BookID)
Please help, now for 3 levels, what table I have to add and what changes I have to do in below code
Code:Function tvwBooks_Fill() 'Created by Helen Feddema 2-10-2002 'Last modified 4-23-2002 '============================================================ 'Modified from a procedure generated by the Access 97 'Treeview Control Wizard 'PURPOSE: Fill the ActiveX Treeview Control 'tvwBooks' with 'author and book information 'ACCEPTS: Nothing 'RETURNS: Nothing 'CALLED FROM: Form Load event '============================================================ On Error GoTo ErrorHandler Dim strMessage As String Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim intVBMsg As Integer Dim strQuery1 As String Dim strQuery2 As String Dim nod As Object Dim strNode1Text As String Dim strNode2Text As String Dim strVisibleText As String Set dbs = CurrentDb() strQuery1 = "qryEBookAuthors" strQuery2 = "qryEBooksByAuthor" With Me![tvwBooks] 'Fill Level 1 Set rst = dbs.OpenRecordset(strQuery1, dbOpenForwardOnly) 'Add a node object for each record in the "qryEBookAuthors" table/query. 'The Key argument concatenates the level number and the LastNameFirst 'field of the Level 1 query, to create a unique key value for the node. 'The Text argument is the text displayed as a Level 1 node in the 'TreeView control Do Until rst.EOF strNode1Text = StrConv("Level1" & rst![LastNameFirst], _ vbLowerCase) Set nod = .Nodes.Add(Key:=strNode1Text, _ Text:=rst![LastNameFirst]) 'Expand the entire node nod.Expanded = True rst.MoveNext Loop rst.Close 'Fill Level 2 Set rst = dbs.OpenRecordset(strQuery2, dbOpenForwardOnly) 'Add a node object for each record in the "qryEBooksByAuthor" 'table/query. 'The value of the Relative argument matches the Key argument value 'for the Level 1 node this Level 2 node belongs to. 'The Relationship argument takes a named constant, tvwChild, 'indicating that the Level 2 node becomes a child node of the 'Level 1 node named in the Relative argument. 'The Key argument concatenates the level number and the Title 'field of the Level 2 query, to create a unique key value for the node. 'The Text argument is the text displayed as a Level 2 node in the 'TreeView control Do Until rst.EOF strNode1Text = StrConv("Level1" & rst![LastNameFirst], vbLowerCase) strNode2Text = StrConv("Level2" & rst![Title], vbLowerCase) strVisibleText = rst![Title] .Nodes.Add relative:=strNode1Text, _ relationship:=tvwChild, _ Key:=strNode2Text, _ Text:=strVisibleText rst.MoveNext Loop rst.Close End With dbs.Close ErrorHandlerExit: Exit Function ErrorHandler: Select Case Err.Number Case 35601 'Element not found strMessage = "Possible Causes: You selected a table/query" _ & " for a child level which does not correspond to a value" _ & " from its parent level." intVBMsg = MsgBox(Error$ & strMessage, vbOKOnly + _ vbExclamation, "Run-time Error: " & Err.Number) Case 35602 'Key is not unique in collection strMessage = "Possible Causes: You selected a non-unique" _ & " field to link levels." intVBMsg = MsgBox(Error$ & strMessage, vbOKOnly + _ vbExclamation, "Run-time Error: " & Err.Number) Case Else intVBMsg = MsgBox(Error$ & "@@", vbOKOnly + _ vbExclamation, "Run-time Error: " & Err.Number) End Select Resume ErrorHandlerExit End Function