Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a filter to a treeview via a toggle button 1

Status
Not open for further replies.

baboudi

Technical User
Oct 18, 2007
34
GB
Hi all,

I have been struggling to do this and hope someone can help.

I have 3 tables which is of concern
1. Building (buildingID, BuildingName, NotActive)
2. Floors (FloorID, BuildingID, Floorlevel)
3. Checklist (floorid, checklistid, checklist, Comments, Review)


I created a treeview in acces 2003 to filter the checklist per building/floor. When clicking on the different floor in the treeview, it gives the corresponding checklist items on a subform. The subform is mainly the checklist table.

Now, in some case, some checklist item can be marked for review using a 1/0 field. This Review field is kept in the checklist table

I want to add an additional filter to my treeview to see only reviewed items on request. I.e. a togglebutton, which when clicked will apply a critera of (where review = 1). So that when I navigate through the treeview and click on floors, I can only see the 'marked' items.

clicking the toggle button again, removes the filter

many thanks for your help
 
You could do it several ways.
1)reload the treeview based on a different query or set of queries including only the reviewed records.
2)read a query of not reviewed items. Set these nodes to visible = false. Make another procedure to set them back to visble.
 
3) when loading the treeview set the Tag property to "Reviewed" or "Not Reviewed". Then you do not have to read from a query just loop the nodes. If "Not Reviewed" node.visible = false
 
Thanks MajP

What I did was to add a filter option from the main form via a toggle button. When pressed, it will filter the records in the subform.

However, your option 3 is actually very good if I understood it properly. So it will check if there is any records as reviewed, and if not will not display the node.

I wil investigate the tag property and will let you know how I managed.

Thanks again
 
Not sure if I fully understand what is in the tree and what is in the subform.

I often use treeviews with several filter buttons. The filter actually reloads the treeview based on a different query/queries. This works well if you do not have a large amount of nodes that take time to load.
 
Let me clarify.

on the treeview I have buildings as the Parent nodes and floors as the child nodes.
When clicking on floors, it will show the corresponding items in the subform.

now, i have a toggle button with a filter to apply the Reviewed = -1 criteria on the subform (Reviewed field is in the Checklist table) to show only the Reviewed item when I click on floors.

The issue now, is that, I have to go through each floor in the treeview to see if there is Reviewed items.

So I was hoping to be able to disable any child floor nodes which doesnt contain any Reviewed items.

Hope that this is actually possible
I have been looking for documenation about using the Tag property, but there's not much.

thanks
 
The tag property is simply a property of the node.
tvw.nodes("yourKey").tag = "Reviewed"
So set this property when loading your nodes.

Then
for each node in treeview.nodes
if not node.tag = "reviewed" then node.visible = false.
(pseudo code)

I do not know how you are loading the tree but I assume you have a bldg query and a floor query. If you simply have a reviewed floor query (a select query returning only floors that have reviewed items) then reload the tree with your bldg query and the reviewed floor query. To unfilter reload the tree with your bldg query and the all floors query.

So yes this is very doable either way.
 
Actually both nodes uses tables to get populated.
Then associate it to the Checklists items in the subform using the master and child fields properties.

I don't understand how the tag property work, hence didnt know where to put it exactly.
I end up having element not found when trying to use the tag property.

Floor is my child node, and when I click on a floor it shows the required items in the subform based on the Master/child fields. So I am assuming that when looping through the floor node, it has to check the items on the subform to see if there is any items set to Reviewed.

Happy if you can show me where to put it, below is the code to create the nodes.

Private Sub CreateBuildingNodes()
Dim rst As DAO.Recordset
Set rst = CurrentDb.TableDefs!tblbuilding.OpenRecordset

rst.MoveFirst
Do Until rst.EOF
With Me.tvwCatgeory.Nodes.Add(Text:=rst!Building, Key:="Cat=" & CStr(rst!BdgID))

End With
rst.MoveNext
Loop
End Sub

Private Sub CreateFloorNodes()
Dim rst As DAO.Recordset

Set rst = CurrentDb.TableDefs!tblFloor.OpenRecordset

rst.MoveFirst
Do Until rst.EOF
With Me.tvwCatgeory.Nodes.Add(Relationship:=tvwChild, Relative:="Cat=" & CStr(rst!BdgID), _
Text:=rst!Floor, Key:="SubCat=" & CStr(rst!FloorID))
'tvwCatgeory.Nodes("Cat").Tag = "Reviewed"
End With
rst.MoveNext
Loop

End Sub


Thanks again for your help
 
so just use a query here that returns only the desired nodes

Set rst = CurrentDb.TableDefs!tblFloor.OpenRecordset

and reload the tree. You have to delete all the nodes in the tree before reloading. There is a nodes clear event.

But your use of the tag looks correct. I run this in my code

Set currentNode = mTVW.Nodes.Add(, , currentID, currentText)
currentNode.Tag = currentIdentifier

with no problem. When I click on the node the identifier tells me which table it came from.
 
Thanks a lot for your time MajP, I will give this a go.
 
You may try something like this in your CreateFloorNodes sub:
Code:
    With Me.tvwCatgeory.Nodes.Add(Relationship:=tvwChild, Relative:="Cat=" & CStr(rst!BdgID), _
        Text:=rst!Floor, Key:="SubCat=" & CStr(rst!FloorID))
        If rst!Review Then
          .Tag = "Reviewed"
        End If
    End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Your error
"element not found"
Is a poor MS error message. This message is the same as "no such index".

So you must not have a node with a key of "Cat"
'tvwCatgeory.Nodes("Cat").Tag = "Reviewed"

The add function of the nodes collection actually returns the newly created node after adding it to the collection. So I find that the easiest way to set additional properties is to declare a node. Ex
Code:
dim catNode as node

set catNode = Me.tvwCatgeory.Nodes.Add(Relationship:=tvwChild, Relative:="Cat=" & CStr(rst!BdgID), _
        Text:=rst!Floor, Key:="SubCat=" & CStr(rst!FloorID))

with catNode
  .tag =
  .otherproperty =
  .otherproperty =
end with
 
Thanks PHV. Still got the same error using
If rst!Review Then
.Tag = "Reviewed"

MajP, could it be the reason of the element not found is because in my Floor table (the child nodes), there is no field for the 'Review'. This is actually in the Items table (the subform). I just added a field Review as a test to the Floor table and it compiled.


If So, I will try to do your other suggestion MajP to use a query for the floor node which will return only the required floors and reload the required nodes

 
I apologize. I beleive I sent you down the wrong path at first. The visible property of a Node is a read only property. I think is has to do with if it can be seen in the current window. Now I know why I always reload the tree based on a different recordset when I filter.

You could delete the desired nodes, but then you would have to reload them anyways.
 
No need for any apologizes, your help was very much apprciated and have my treeview almost completed not when applying the filter.
I clear the nodes, and reload the treeview based on a query.
 
Im nearly there, but need an extra help....

I have a toggle button which is suppose to reload the treeview, based this time on query (with the Reviewed filtered)

Private Sub Toggle12_Click()
xProductTreeview.Nodes.Clear

however not sure how to add the treeview nodes after this and keep having ambiguous name. I dont want to change any Key value as they are used to get the node name and send it to the subform

Private Sub CreateBuildingNodes()
Dim rst As DAO.Recordset
Set rst = CurrentDb.QueryDefs!qryBdgReview.OpenRecordset

rst.MoveFirst
Do Until rst.EOF
With Me.tvwCatgeory.Nodes.Add(Text:=rst!Building, Key:="Cat=" & CStr(rst!BdgID))

End With
rst.MoveNext
Loop
End Sub


Thanks again
 
got it

Private Sub Toggle12_Click()
xProductTreeview.Nodes.Clear
SetupTreeview
CreateFilteredbdgNodes
CreateFilteredFloorNodes


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top