Treeview

  • Thread starter Surveyor in VA via AccessMonster.com
  • Start date
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
 
S

Shiller

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

Hey Surveyor,

You need a reference to Microsoft Windows Common Controls.

The solution is to open any module in Design view, then select Tools >
References > Browse.

Change the "Files of type" to "ActiveX Control *(.ocx)"

Search for and select MSCOMCTL.OCX, or COMCTL32.OCX

Click on "Open" to finish the process.

let me know if it works.

Shiller

http://sites.google.com/site/microsoftaccesstips/
 
S

Surveyor in VA via AccessMonster.com

Thank you for the suggestion. I did make sure the Common Controls reference
was selected. I found in another post that when defining my variables the
following needed to be modified:
Dim nodCurrent As MSComctlLib.Node, nodRoot As MSComctlLib.Node
Dim objTree

After I did this, it appears to of populated the tree, however I am not
getting any +/- icons in front of trees with a child node.

Thanks again for the help!
Chris F
[quoted text clipped - 50 lines]
Hey Surveyor,

You need a reference to Microsoft Windows Common Controls.

The solution is to open any module in Design view, then select Tools >
References > Browse.

Change the "Files of type" to "ActiveX Control *(.ocx)"

Search for and select MSCOMCTL.OCX, or COMCTL32.OCX

Click on "Open" to finish the process.

let me know if it works.

Shiller

http://sites.google.com/site/microsoftaccesstips/
 
R

Rob Parker

You set the appearance of the treeview control via its properties.
Right-click on the control in your form in design view, select
TreeCtrlObject | Properties, then chose a Style which includes "PlusMinus"
in its description.

HTH,

Rob

Surveyor in VA via AccessMonster.com said:
Thank you for the suggestion. I did make sure the Common Controls
reference
was selected. I found in another post that when defining my variables the
following needed to be modified:
Dim nodCurrent As MSComctlLib.Node, nodRoot As MSComctlLib.Node
Dim objTree

After I did this, it appears to of populated the tree, however I am not
getting any +/- icons in front of trees with a child node.

Thanks again for the help!
Chris F
[quoted text clipped - 50 lines]
Hey Surveyor,

You need a reference to Microsoft Windows Common Controls.

The solution is to open any module in Design view, then select Tools >
References > Browse.

Change the "Files of type" to "ActiveX Control *(.ocx)"

Search for and select MSCOMCTL.OCX, or COMCTL32.OCX

Click on "Open" to finish the process.

let me know if it works.

Shiller

http://sites.google.com/site/microsoftaccesstips/
 
T

tobesurveyor via AccessMonster.com

Thanks Rob! I appreciate the help. I had to set as the PlusMinus as you
suggested but also found I had to change the the Linestyle for 0 to 1.

I am reading up on posts now on Error 35602: Key is not Unique in collection.
I am using two separate tables to populate my tree, one as the parent the
other as the child, and my keys are in fact the autonumber ID from each
(which can be the same, which I believe is generating the error).

However I thought I corrected the problem by changing the prefix of the key
from "a" to "b" in the child node function but it is still generating the
error on when it tries to populate the child node.

This is set on Form_Load for my root (tblSACCat):
Set nodCurrent = objTree.Nodes.Add(, , "a" & rst!SACCatID, strText)

This is set on my function to pass through all my records for my child nodes
Set nodCurrent = objTree.Nodes.Add(nodBoss, tvwChild, "b" & _
rst!SACSubID, strText)



Rob said:
You set the appearance of the treeview control via its properties.
Right-click on the control in your form in design view, select
TreeCtrlObject | Properties, then chose a Style which includes "PlusMinus"
in its description.

HTH,

Rob
Thank you for the suggestion. I did make sure the Common Controls
reference
[quoted text clipped - 36 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Unique Key in Treeview 2
Challenging Recordset 1
Problem with Treeview code 3
Treeview Control Problem 2
Problem with Tree View 2
Filtering Sub Form 1
no one is helping... 2
treeview control issue 1

Top