masoud_sedighy
Registered User.
- Local time
- Yesterday, 20:37
- Joined
- Dec 10, 2011
- Messages
- 132
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
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
[FONT="]1. [/FONT][FONT="]Function tvwBooks_Fill()[/FONT][FONT="]2. [/FONT][FONT="]'Created by Helen Feddema 2-10-2002[/FONT][FONT="]3. [/FONT][FONT="]'Last modified 4-23-2002[/FONT][FONT="]4. [/FONT][FONT="] [/FONT][FONT="]5. [/FONT][FONT="]'============================================================[/FONT][FONT="]6. [/FONT][FONT="]'Modified from a procedure generated by the Access 97[/FONT][FONT="]7. [/FONT][FONT="]'Treeview Control Wizard[/FONT][FONT="]8. [/FONT][FONT="] [/FONT][FONT="]9. [/FONT][FONT="]'PURPOSE: Fill the ActiveX Treeview Control 'tvwBooks' with[/FONT][FONT="]10.[/FONT][FONT="]'author and book information[/FONT][FONT="]11.[/FONT][FONT="]'ACCEPTS: Nothing[/FONT][FONT="]12.[/FONT][FONT="]'RETURNS: Nothing[/FONT][FONT="]13.[/FONT][FONT="]'CALLED FROM: Form Load event[/FONT][FONT="]14.[/FONT][FONT="]'============================================================[/FONT][FONT="]15.[/FONT][FONT="] [/FONT][FONT="]16.[/FONT][FONT="]On Error GoTo ErrorHandler[/FONT][FONT="]17.[/FONT][FONT="] [/FONT][FONT="]18.[/FONT][FONT="] Dim strMessage As String[/FONT][FONT="]19.[/FONT][FONT="] Dim dbs As DAO.Database[/FONT][FONT="]20.[/FONT][FONT="] Dim rst As DAO.Recordset[/FONT][FONT="]21.[/FONT][FONT="] Dim intVBMsg As Integer[/FONT][FONT="]22.[/FONT][FONT="] Dim strQuery1 As String[/FONT][FONT="]23.[/FONT][FONT="] Dim strQuery2 As String[/FONT][FONT="]24.[/FONT][FONT="] Dim nod As Object[/FONT][FONT="]25.[/FONT][FONT="] Dim strNode1Text As String[/FONT][FONT="]26.[/FONT][FONT="] Dim strNode2Text As String[/FONT][FONT="]27.[/FONT][FONT="] Dim strVisibleText As String[/FONT][FONT="]28.[/FONT][FONT="] [/FONT][FONT="]29.[/FONT][FONT="] Set dbs = CurrentDb()[/FONT][FONT="]30.[/FONT][FONT="] strQuery1 = "qryEBookAuthors"[/FONT][FONT="]31.[/FONT][FONT="] strQuery2 = "qryEBooksByAuthor"[/FONT][FONT="]32.[/FONT][FONT="] [/FONT][FONT="]33.[/FONT][FONT="] With Me![tvwBooks][/FONT][FONT="]34.[/FONT][FONT="] 'Fill Level 1[/FONT][FONT="]35.[/FONT][FONT="] Set rst = dbs.OpenRecordset(strQuery1, dbOpenForwardOnly)[/FONT][FONT="]36.[/FONT][FONT="] [/FONT][FONT="]37.[/FONT][FONT="] 'Add a node object for each record in the "qryEBookAuthors" table/query.[/FONT][FONT="]38.[/FONT][FONT="] 'The Key argument concatenates the level number and the LastNameFirst[/FONT][FONT="]39.[/FONT][FONT="] 'field of the Level 1 query, to create a unique key value for the node.[/FONT][FONT="]40.[/FONT][FONT="] 'The Text argument is the text displayed as a Level 1 node in the[/FONT][FONT="]41.[/FONT][FONT="] 'TreeView control[/FONT][FONT="]42.[/FONT][FONT="] [/FONT][FONT="]43.[/FONT][FONT="] Do Until rst.EOF[/FONT][FONT="]44.[/FONT][FONT="] strNode1Text = StrConv("Level1" & rst![LastNameFirst], _[/FONT][FONT="]45.[/FONT][FONT="] vbLowerCase)[/FONT][FONT="]46.[/FONT][FONT="] Set nod = .Nodes.Add(Key:=strNode1Text, _[/FONT][FONT="]47.[/FONT][FONT="] Text:=rst![LastNameFirst])[/FONT][FONT="]48.[/FONT][FONT="] 'Expand the entire node[/FONT][FONT="]49.[/FONT][FONT="] nod.Expanded = True[/FONT][FONT="]50.[/FONT][FONT="] rst.MoveNext[/FONT][FONT="]51.[/FONT][FONT="] Loop[/FONT][FONT="]52.[/FONT][FONT="] rst.Close[/FONT][FONT="]53.[/FONT][FONT="] [/FONT][FONT="]54.[/FONT][FONT="] 'Fill Level 2[/FONT][FONT="]55.[/FONT][FONT="] Set rst = dbs.OpenRecordset(strQuery2, dbOpenForwardOnly)[/FONT][FONT="]56.[/FONT][FONT="] [/FONT][FONT="]57.[/FONT][FONT="] 'Add a node object for each record in the "qryEBooksByAuthor"[/FONT][FONT="]58.[/FONT][FONT="] 'table/query.[/FONT][FONT="]59.[/FONT][FONT="] 'The value of the Relative argument matches the Key argument value[/FONT][FONT="]60.[/FONT][FONT="] 'for the Level 1 node this Level 2 node belongs to.[/FONT][FONT="]61.[/FONT][FONT="] 'The Relationship argument takes a named constant, tvwChild,[/FONT][FONT="]62.[/FONT][FONT="] 'indicating that the Level 2 node becomes a child node of the[/FONT][FONT="]63.[/FONT][FONT="] 'Level 1 node named in the Relative argument.[/FONT][FONT="]64.[/FONT][FONT="] 'The Key argument concatenates the level number and the Title[/FONT][FONT="]65.[/FONT][FONT="] 'field of the Level 2 query, to create a unique key value for the node.[/FONT][FONT="]66.[/FONT][FONT="] 'The Text argument is the text displayed as a Level 2 node in the[/FONT][FONT="]67.[/FONT][FONT="] 'TreeView control[/FONT][FONT="]68.[/FONT][FONT="] [/FONT][FONT="]69.[/FONT][FONT="] Do Until rst.EOF[/FONT][FONT="]70.[/FONT][FONT="] strNode1Text = StrConv("Level1" & rst![LastNameFirst], vbLowerCase)[/FONT][FONT="]71.[/FONT][FONT="] strNode2Text = StrConv("Level2" & rst![Title], vbLowerCase)[/FONT][FONT="]72.[/FONT][FONT="] strVisibleText = rst![Title][/FONT][FONT="]73.[/FONT][FONT="] .Nodes.Add relative:=strNode1Text, _[/FONT][FONT="]74.[/FONT][FONT="] relationship:=tvwChild, _[/FONT][FONT="]75.[/FONT][FONT="] Key:=strNode2Text, _[/FONT][FONT="]76.[/FONT][FONT="] Text:=strVisibleText[/FONT][FONT="]77.[/FONT][FONT="] rst.MoveNext[/FONT][FONT="]78.[/FONT][FONT="] Loop[/FONT][FONT="]79.[/FONT][FONT="] rst.Close[/FONT][FONT="]80.[/FONT][FONT="] [/FONT][FONT="]81.[/FONT][FONT="] End With[/FONT][FONT="]82.[/FONT][FONT="] dbs.Close[/FONT][FONT="]83.[/FONT][FONT="] [/FONT][FONT="]84.[/FONT][FONT="]ErrorHandlerExit:[/FONT][FONT="]85.[/FONT][FONT="] Exit Function[/FONT][FONT="]86.[/FONT][FONT="] [/FONT][FONT="]87.[/FONT][FONT="]ErrorHandler:[/FONT][FONT="]88.[/FONT][FONT="] Select Case Err.Number[/FONT][FONT="]89.[/FONT][FONT="] Case 35601[/FONT][FONT="]90.[/FONT][FONT="] 'Element not found[/FONT][FONT="]91.[/FONT][FONT="] strMessage = "Possible Causes: You selected a table/query" _[/FONT][FONT="]92.[/FONT][FONT="] & " for a child level which does not correspond to a value" _[/FONT][FONT="]93.[/FONT][FONT="] & " from its parent level."[/FONT][FONT="]94.[/FONT][FONT="] intVBMsg = MsgBox(Error$ & strMessage, vbOKOnly + _[/FONT][FONT="]95.[/FONT][FONT="] vbExclamation, "Run-time Error: " & Err.Number)[/FONT][FONT="]96.[/FONT][FONT="] Case 35602[/FONT][FONT="]97.[/FONT][FONT="] 'Key is not unique in collection[/FONT][FONT="]98.[/FONT][FONT="] strMessage = "Possible Causes: You selected a non-unique" _[/FONT][FONT="]99.[/FONT][FONT="] & " field to link levels."[/FONT][FONT="]100. [/FONT][FONT="] intVBMsg = MsgBox(Error$ & strMessage, vbOKOnly + _[/FONT][FONT="]101. [/FONT][FONT="] vbExclamation, "Run-time Error: " & Err.Number)[/FONT][FONT="]102. [/FONT][FONT="] Case Else[/FONT][FONT="]103. [/FONT][FONT="] intVBMsg = MsgBox(Error$ & "@@", vbOKOnly + _[/FONT][FONT="]104. [/FONT][FONT="] vbExclamation, "Run-time Error: " & Err.Number)[/FONT][FONT="]105. [/FONT][FONT="] End Select[/FONT][FONT="]106. [/FONT][FONT="] Resume ErrorHandlerExit[/FONT][FONT="]107. [/FONT][FONT="] [/FONT][FONT="]108. [/FONT][FONT="]End Function[/FONT][FONT="] [/FONT]
Last edited: