I like to use the treeview for the first time, but some strange problems come to me:
references: OLE automation, DAO 3.6, Common Controls 6.0, Data access componennt Installed version, Jet and Replication objects
Access closed with a error Access.aplication.exe after running the code.
I think the code below make a tree like:
+ first floor
- room 2
- room 4
+ second floor
- room 12
- room 44
enz.
but it doesn't work at all, maybe some failures in the properties of the treeview? I hope somebody can help me.
Thnx,
Gerard
Public Sub MaakBoom()
On Error GoTo err_Handler
Dim DB As DAO.Database, RS1 As DAO.Recordset, RS2 As DAO.Recordset
Dim strLocKey As String, strSubKey As String
Dim strSQL1 As String, strSQL2 As String
Set DB = CurrentDb
' Open recordset and loop through it to fill TreeView control
strSQL1 = "SELECT * FROM tblLocatie WHERE werkbonRef = " & Me.werkbon_ID & _
" ORDER BY volgorde"
Set RS1 = DB.OpenRecordset(strSQL1, dbOpenForwardOnly)
Do Until RS1.EOF
strLocKey = StrConv("o" & RS1!locatie_ID, vbLowerCase)
Me!axTreeView.Nodes.Add , , strLocKey, RS1!Loc_omschrijving
strSQL2 = "SELECT * FROM tblsubLocatie WHERE LocatieRef = " & RS1!locatie_ID
' Fill Level 2.
Set RS2 = DB.OpenRecordset(strSQL2, dbOpenForwardOnly)
Do Until RS2.EOF
' Link to Level 1 by referencing the CustomerID key and set
' the node as a child node of Level 1. Use "o" and the
' StrConv() function in the new Key property for Level 2,
' because OrderID is a numeric field.
strSubKey = StrConv("s" & RS2!Sublocatie_ID, vbLowerCase)
Me!axTreeView.Nodes.Add strLocKey, tvwChild, strSubKey, _
RS2!Sub_omschrijving
RS2.MoveNext
Loop
RS2.Close
RS1.MoveNext
Loop
RS1.Close
' ' Fill Level 3.
' Set RS = DB.OpenRecordset("Order Details", dbOpenForwardOnly)
' Do Until RS.EOF
' ' Link to Level 2 by referencing the strOrderKey key and set
' ' the node as a child node of Level 2.
' ' Product Key is made alpha with "p" for parsing in cmdOpenForm_Click
' strOrderKey = StrConv("o" & RS!OrderID, vbLowerCase)
' strProductKey = StrConv(strOrderKey & "p" & RS!ProductID, vbLowerCase)
' Me!axTreeView.Nodes.Add strOrderKey, tvwChild, strProductKey, _
' RS!ProductID & " " & Format(RS!UnitPrice, "Currency"
' RS.MoveNext
' Loop
' RS.Close
Set RS1 = Nothing
Set RS2 = Nothing
Set DB = Nothing
references: OLE automation, DAO 3.6, Common Controls 6.0, Data access componennt Installed version, Jet and Replication objects
Access closed with a error Access.aplication.exe after running the code.
I think the code below make a tree like:
+ first floor
- room 2
- room 4
+ second floor
- room 12
- room 44
enz.
but it doesn't work at all, maybe some failures in the properties of the treeview? I hope somebody can help me.
Thnx,
Gerard
Public Sub MaakBoom()
On Error GoTo err_Handler
Dim DB As DAO.Database, RS1 As DAO.Recordset, RS2 As DAO.Recordset
Dim strLocKey As String, strSubKey As String
Dim strSQL1 As String, strSQL2 As String
Set DB = CurrentDb
' Open recordset and loop through it to fill TreeView control
strSQL1 = "SELECT * FROM tblLocatie WHERE werkbonRef = " & Me.werkbon_ID & _
" ORDER BY volgorde"
Set RS1 = DB.OpenRecordset(strSQL1, dbOpenForwardOnly)
Do Until RS1.EOF
strLocKey = StrConv("o" & RS1!locatie_ID, vbLowerCase)
Me!axTreeView.Nodes.Add , , strLocKey, RS1!Loc_omschrijving
strSQL2 = "SELECT * FROM tblsubLocatie WHERE LocatieRef = " & RS1!locatie_ID
' Fill Level 2.
Set RS2 = DB.OpenRecordset(strSQL2, dbOpenForwardOnly)
Do Until RS2.EOF
' Link to Level 1 by referencing the CustomerID key and set
' the node as a child node of Level 1. Use "o" and the
' StrConv() function in the new Key property for Level 2,
' because OrderID is a numeric field.
strSubKey = StrConv("s" & RS2!Sublocatie_ID, vbLowerCase)
Me!axTreeView.Nodes.Add strLocKey, tvwChild, strSubKey, _
RS2!Sub_omschrijving
RS2.MoveNext
Loop
RS2.Close
RS1.MoveNext
Loop
RS1.Close
' ' Fill Level 3.
' Set RS = DB.OpenRecordset("Order Details", dbOpenForwardOnly)
' Do Until RS.EOF
' ' Link to Level 2 by referencing the strOrderKey key and set
' ' the node as a child node of Level 2.
' ' Product Key is made alpha with "p" for parsing in cmdOpenForm_Click
' strOrderKey = StrConv("o" & RS!OrderID, vbLowerCase)
' strProductKey = StrConv(strOrderKey & "p" & RS!ProductID, vbLowerCase)
' Me!axTreeView.Nodes.Add strOrderKey, tvwChild, strProductKey, _
' RS!ProductID & " " & Format(RS!UnitPrice, "Currency"
' RS.MoveNext
' Loop
' RS.Close
Set RS1 = Nothing
Set RS2 = Nothing
Set DB = Nothing