It took some time, but I'll have created a 2-level treeview, but now for the first time I would like to go 5-levels deep, but trying to add the third level it gives me an error.
Till now I have programmed:
After opening the form, it gives me error: 35601
When I change level 3 as follows:
It won't give me any error, but then it will add the third level as a secondlevel. I know that is is because of: .Nodes.Add relative:=strNode1Text. But can't figure out why it won't work for the third level.
After adding this one, I still have to add 2 more.
The treeview will be used for editing a Price Set, a complex set of tables, but with a treeview it will be simple to change etc.
Hopefully someone can help me further.
Till now I have programmed:
Code:
Function tvwTicketSets_Fill()
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 strQuery3 As String
Dim nod As Object
Dim strNode1Text As String
Dim strNode2Text As String
Dim strNode3Text As String
Dim strVisibleText1 As String
Dim strVisibleText2 As String
Dim strVisibleText3 As String
Set dbs = CurrentDb()
strQuery1 = "Ticketset"
strQuery2 = "TicketsetsPrijstypesForTvw"
strQuery3 = "TicketsetsDagForTvw"
With Me![tvwTicketsets]
'Fill Level 1
Set rst = dbs.OpenRecordset(strQuery1, dbOpenForwardOnly)
Do Until rst.EOF
Debug.Print "Adding Level 1 item: " & rst![TicketsetId]
strNode1Text = StrConv("Level1 - " & rst![TicketsetId], _
vbLowerCase)
Debug.Print "Node 1 text: " & strNode1Text
strVisibleText1 = rst![Titel]
Debug.Print "Level 1 visible text: " & strVisibleText1
Set nod = .Nodes.Add(Key:=strNode1Text, _
Text:=strVisibleText1)
nod.Expanded = True
rst.MoveNext
Loop
rst.Close
'Fill Level 2
Set rst = dbs.OpenRecordset(strQuery2, dbOpenForwardOnly)
Do Until rst.EOF
Debug.Print "Adding Level 2 item: " & rst![TicketsetId]
strNode1Text = StrConv("Level1 - " & rst![TicketsetId], vbLowerCase)
Debug.Print "Node 1 text: "; strNode1Text
strNode2Text = StrConv("Level2 - " & rst![Ticketset_PrijstypesId] & " - " _
& rst![Titel], vbLowerCase)
Debug.Print "Node 2 text: " & strNode2Text
strVisibleText2 = rst![Titel]
Debug.Print "Visible text: " & strVisibleText2
.Nodes.Add relative:=strNode1Text, _
relationship:=tvwChild, _
Key:=strNode2Text, _
Text:=strVisibleText2
rst.MoveNext
Loop
rst.Close
'Fill Level 3
Set rst = dbs.OpenRecordset(strQuery3, dbOpenForwardOnly)
Do Until rst.EOF
Debug.Print "Adding Level 3 item: " & rst![Ticketset_PrijstypesId]
strNode2Text = StrConv("Level2 - " & rst![Ticketset_PrijstypesId], vbLowerCase)
Debug.Print "Node 2 text: "; strNode2Text
strNode3Text = StrConv("Level3 - " & rst![Ticketset_GeldigOpDagId] & " - " _
& rst![Titel], vbLowerCase)
Debug.Print "Node 3 text: " & strNode3Text
strVisibleText3 = rst![Titel]
Debug.Print "Visible text: " & strVisibleText3
.Nodes.Add relative:=strNode2Text, _
relationship:=tvwChild, _
Key:=strNode3Text, _
Text:=strVisibleText3
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
After opening the form, it gives me error: 35601
When I change level 3 as follows:
Code:
'Fill Level 3
Set rst = dbs.OpenRecordset(strQuery3, dbOpenForwardOnly)
Do Until rst.EOF
Debug.Print "Adding Level 3 item: " & rst![Ticketset_PrijstypesId]
strNode2Text = StrConv("Level2 - " & rst![Ticketset_PrijstypesId], vbLowerCase)
Debug.Print "Node 2 text: "; strNode2Text
strNode3Text = StrConv("Level3 - " & rst![Ticketset_GeldigOpDagId] & " - " _
& rst![Titel], vbLowerCase)
Debug.Print "Node 3 text: " & strNode3Text
strVisibleText3 = rst![Titel]
Debug.Print "Visible text: " & strVisibleText3
.Nodes.Add relative:=strNode1Text, _
relationship:=tvwChild, _
Key:=strNode3Text, _
Text:=strVisibleText3
rst.MoveNext
Loop
rst.Close
After adding this one, I still have to add 2 more.
The treeview will be used for editing a Price Set, a complex set of tables, but with a treeview it will be simple to change etc.
Hopefully someone can help me further.