S
Surveyor in VA via AccessMonster.com
Hello-
I am trying to use the tree view control and have modified some code found on
the Microsoft website KB 209898 in Access 2007. This is my first attempt so
I am just learning the ropes of this complex, but usefull control.
I copy the code on the Form_Load event and when the form opens, there is an
error generated saying Runtime Error 13: Type mismatch. It highlights this
code: Set objTree = Me.xTree.Object
I have pasted the entire snipet here. Any help would be greatly appreciated.
Regards, Chris F.
Private Sub Form_Load()
Dim db As Database
Dim rst As Recordset
Dim nodCurrent As Node, nodRoot As Node
Dim objTree As TreeView
Dim strText As String, bk As String
Set db = CurrentDb
'Open the Employees table.
Set rst = db.OpenRecordset("q", dbOpenDynaset, dbReadOnly)
'Create a reference to the TreeView Control.
Set objTree = Me.xTree.Object
'Find the first employee who is a supervisor.
rst.FindFirst "[SAChecklistID] = 1"
'Build the TreeView list of supervisors and their employees.
Do Until rst.NoMatch
'Extract the supervisor's name.
strText = rst![OrderNo] & (", " + rst![CategoryName])
'Add a root level node to the tree for the supervisor.
Set nodCurrent = objTree.Nodes.Add(, , "a" & rst!SACCatID, _
strText)
'Use a placeholder to save this place in the recordset.
bk = rst.Bookmark
'Run a recursive procedure to add all the child nodes
'for employees who report to this supervisor.
'AddChildren nodCurrent, rst
'Return to your placeholder.
rst.Bookmark = bk
'Find the next supervisor.
rst.FindNext "[SAChecklistID] = 1"
Loop
End Sub
I am trying to use the tree view control and have modified some code found on
the Microsoft website KB 209898 in Access 2007. This is my first attempt so
I am just learning the ropes of this complex, but usefull control.
I copy the code on the Form_Load event and when the form opens, there is an
error generated saying Runtime Error 13: Type mismatch. It highlights this
code: Set objTree = Me.xTree.Object
I have pasted the entire snipet here. Any help would be greatly appreciated.
Regards, Chris F.
Private Sub Form_Load()
Dim db As Database
Dim rst As Recordset
Dim nodCurrent As Node, nodRoot As Node
Dim objTree As TreeView
Dim strText As String, bk As String
Set db = CurrentDb
'Open the Employees table.
Set rst = db.OpenRecordset("q", dbOpenDynaset, dbReadOnly)
'Create a reference to the TreeView Control.
Set objTree = Me.xTree.Object
'Find the first employee who is a supervisor.
rst.FindFirst "[SAChecklistID] = 1"
'Build the TreeView list of supervisors and their employees.
Do Until rst.NoMatch
'Extract the supervisor's name.
strText = rst![OrderNo] & (", " + rst![CategoryName])
'Add a root level node to the tree for the supervisor.
Set nodCurrent = objTree.Nodes.Add(, , "a" & rst!SACCatID, _
strText)
'Use a placeholder to save this place in the recordset.
bk = rst.Bookmark
'Run a recursive procedure to add all the child nodes
'for employees who report to this supervisor.
'AddChildren nodCurrent, rst
'Return to your placeholder.
rst.Bookmark = bk
'Find the next supervisor.
rst.FindNext "[SAChecklistID] = 1"
Loop
End Sub