Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / October 2008

Tip: Looking for answers? Try searching our database.

I am using a tree control (MSComctlLib.TreeCtrl.2) in a form...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
billmahon - 15 Feb 2008 20:45 GMT
and want to be able to change the font color of items in the tree based on
certain criteria.  Also, I would like to display information about the item
highlighted on the tree control onto another part of the form by passing the
value of the item on the tree control into the forms query.  Can anyone help?
Rob Parker - 16 Feb 2008 03:29 GMT
You can set the color of a particular node via code such as:
   nodx.ForeColor = vbRed  'using named colors
or
   nodx.ForeColor = RGB(255,0,128)  'using rgb colors
or
   nodx.ForeColor = 4194432  'using color code as in Access properties

Just put the statement into an If statement while you're loading the
treeview control to set the color depending on the criteria you want.

Note: For the examples above, I have the following statements in my code :
   Dim nodx As Object
   ...
   Set nodx = TreeView0.Nodes.Add([Relative], [Relationship], [Key],
[Text], [Image], [SelectedImage])
   ...

You can use the NodeClick event of the treeview control to get the Node.Key
and/or Node.Text and/or Node.Tag value of the node you select (either by
clicking on it, or by navigating though the tree with arrow keys).  So, for
example, you could push the information into unbound textboxes on your form
with this code:

Private Sub TreeView0_NodeClick(ByVal Node As Object)
 Me.txtNodeKey = Node.Key
 Me.txtNodeTag = Node.Tag
 Me.txtNodeText = Node.Text
End Sub

Or you could use the key/tag/text value directly in code to find a record in
the form's recordset; or use it to redefine the form's recordsource, or ...

A couple of tips:

Use the Object Browser in the VBA editor to check the properties and methods
available for the Node and Nodes classes, and the properties, methods and
events of the TreeView control.

To enter code into events of the treeview control, select the treeview
control in the object dropdown in the VBA editor, then use the Procedure
dropdown to select the event you want to code for.

HTH,

Rob

> and want to be able to change the font color of items in the tree based on
> certain criteria.  Also, I would like to display information about the
[quoted text clipped - 3 lines]
> value of the item on the tree control into the forms query.  Can anyone
> help?
billmahon - 18 Feb 2008 20:59 GMT
Rob,

Thank you for your quick and helpful reply.  I was able to readily adjust
the node  colors based on the information you provided.

I am still struggling to pass the value of a node into the forms recordset.  
Can you clarify your earlier suggestions?

> You can set the color of a particular node via code such as:
>     nodx.ForeColor = vbRed  'using named colors
[quoted text clipped - 49 lines]
> > value of the item on the tree control into the forms query.  Can anyone
> > help?
Rob Parker - 18 Feb 2008 21:28 GMT
Hi Bill,

I don't understand exactly what you mean by "pass the value of a node into
the forms recordset".  Could you explain exactly what it is that you're
trying to do?

Rob

> Rob,
>
[quoted text clipped - 67 lines]
>> > value of the item on the tree control into the forms query.  Can anyone
>> > help?
billmahon - 18 Feb 2008 22:11 GMT
Yes, I am sorry.

I have a form into which I have inserted a tree control.  The tree shows raw
materials under a Level 1 and level 2 category header.  The window control
works fine.

Now, what I want to do is to display detail information on another part of
the form about a material that is clicked on in the tree control.  The form
is based on a query containing information about each material.

So, in short, what I want to happen is when I select an item in the tree,
the value of that item (most likely the item name, which in your generic
example you referred to as "text") is pushed into the forms query, which then
filters the recordset, and displays detail information about that item on the
form.

I have attached the code I used to populate the tree control.  The forms
query has a field called Suncode which would equal the sparentname.

Private Sub Form_Load()
Dim FormNode As Node
Dim rs As Object
Dim sParentId As String
Dim sProductId As String
Dim sProductName As String
Dim sProductGroupName, sProductGroupKey As String

   With TreeView3
           .Nodes.Clear
           .Indentation = 2
           .Style = 7
           Set FormNode = .Nodes.Add(, , "Root", "Raw Materials " & "(" &
"Green are Core, Red are Non-Core" & ")")
               FormNode.Expanded = True
               
   Set rs = CurrentDb().OpenRecordset("select * from [tblrawmtlclass] order
by [RawMtlClassName]")
   
   Do While Not rs.EOF
       sProductGroupName = rs("RawMtlClassName")
       sProductGroupKey = "g" & rs("RawMtlClassName")
       Set FormNode = .Nodes.Add("Root", tvwChild, sProductGroupKey,
sProductGroupName)
       FormNode.Expanded = False
       rs.MoveNext
       Loop
   Set rs = CurrentDb().OpenRecordset("select * from [qryrawmtlcategories]
order by [rawmtlclassname]")
   Do While Not rs.EOF
   sProductName = rs("rawmtlnature")
   sProductId = "p" & rs("categorycode")
   sParentId = "g" & rs("RawMtlClassName")
   Set FormNode = .Nodes.Add(sParentId, tvwChild, sProductId, sProductName)
   FormNode.Expanded = False
   rs.MoveNext
   Loop
   
   Set rs = CurrentDb().OpenRecordset("select * from [qrytestrawmtlusage]")
   Do While Not rs.EOF
   sProductName = rs("SunCode") & " (" & rs("commonname") & ")"
   sProductId = "p" & rs("SunCode")
   sParentId = "p" & rs("catid")
   If sParentId = "0NA" Then sParentId = "g" & rs("catid")
   Set FormNode = .Nodes.Add(sParentId, tvwChild, sProductId, sProductName)
   FormNode.Expanded = True
    If rs("coremtl?") = True Then
       FormNode.ForeColor = 32768
       FormNode.Bold = True
   End If
   If rs("coremtl?") = False Then
       FormNode.ForeColor = vbRed
       FormNode.Bold = False
   End If
   
   
   rs.MoveNext
   Loop
   End With
   
If Not rs Is Nothing Then rs.close
Set rs = Nothing

       
End Sub
I attempted to use your code.  I placed an unbound text box into the form,
named it txtNodetext.  Then I used the code you provided, and could not get
the value to show up in the text box.

Thanks in advance for your help.

> and want to be able to change the font color of items in the tree based on
> certain criteria.  Also, I would like to display information about the item
> highlighted on the tree control onto another part of the form by passing the
> value of the item on the tree control into the forms query.  Can anyone help?
Rob Parker - 18 Feb 2008 23:06 GMT
Hi Bill,

Got it now.  And it's not hard.

First, the likely reason why you saw nothing in the unbound textbox after
clicking on a node is that you put the textbox in the detail section of the
form; and if you do  that, then you'll need to requery the form to see the
change.  If you put the unbound textbox (txtNodeText) in the form's header,
the new data (the node's text property) will show immediately you click on a
node.  And that's what you need to do here, to get the following to work.
If you don't want to show this textbox in the forms header, you can set its
Visible property to no (and you can even size it so small that you can
collapse the form's header section to almost nothing, if you don't want the
header section to show either).

In the query which is your form's recordsource, add the following in the
criteria row for the field which you want to filter on:
   [forms].[NameOfYourForm].[txtNodeText]

Then, all you need is the following code in the treeview control's NodeClick
event:

Private Sub TreeView0_NodeClick(ByVal Node As Object)
 Me.txtNodeText = Node.Text
 Requery
End Sub

And that's it!

I haven't really looked in any detail at the code you posted, since you say
it works fine.  The only thing I did notice, in a quick skim, is that you
are using a numeric constant to colour nodes green, but a named
colorconstant (vbRed) to color nodes red.  You could use vbGreen in a
similar fashion.  If you want to see which colors you can use in that
manner, type "colorconstant" into the search box in the object browser -
there are 8 of them.

HTH,

Rob

> Yes, I am sorry.
>
[quoted text clipped - 101 lines]
>> value of the item on the tree control into the forms query.  Can anyone
>> help?
billmahon - 19 Feb 2008 22:52 GMT
Worked like a charm.  Thanks again for your help.  

> Hi Bill,
>
[quoted text clipped - 142 lines]
> >> value of the item on the tree control into the forms query.  Can anyone
> >> help?
Brandon Baum - 17 Oct 2008 18:01 GMT
I just got an application that uses this object for maintenance.

When I upgrade the Access application to 2007 this object fails. Is there something I need to add as a reference or is this an object from earlier versions that was removed from 2007?
Arvin Meyer [MVP] - 18 Oct 2008 04:47 GMT
>I just got an application that uses this object for maintenance.
>
> When I upgrade the Access application to 2007 this object fails. Is there
> something I need to add as a reference or is this an object from earlier
> versions that was removed from 2007?

Probably removed, if you find a copy from an older machine, put it in your
Windows System32 directory. Register the file:

Start >>> Run

regsvr32.exe "C:\Windows\System32\comctl32.ocx"

Now set a reference to it in your Access application by opening any code
window and going to:

Tools >>> References

and selecting it.
Signature

Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.