Open limited Treeview

ClaraBarton

Registered User.
Local time
Today, 08:19
Joined
Oct 14, 2019
Messages
848
@MajP In the attached file, I would like to open the Detail form with a limited treeview. I've worked with WhereCondition but that doesn't work. How can I open only the locations that are checked?
 

Attachments

I am not sure I understand. Assume the user selects the following
Check.png


Are you wanting the detail form to have sub treeview that only includes the checked Items?

If so you will need to do some work.
1. add a boolean field to the location and Items table.
2. Loop the tree and update the table marking selected items = true. Mark others false
3. Create a new unionquery that includes only the checked records. (You do not create this each time, just one time.)
4. Re implement the treeview using the new query.
 
I will see if I can demo, but it is not trivial. Another possible approach (never tried), is to open the detail and set the node visible to false except if it was selected on the selection form. Curious if that is even possible.
On that note the class has a Method to getCheckedNodes returning a collection of nodes, which may make this possible.
 
I'm on board with the yes/no column and new query. I actually understand it :sneaky:
And only the locations are on the opening menu form so I only need the column in that table.
 
Okay... turns out I'm not that smart. How do I mark them selected? I added a column called use
Code:
If Not TVW.SelectedNode Is Nothing Then
    For Each nd In TVW.Nodes
         use = True
        End If
    Next nd
 
I added a "Selected" field to both tables.

This code will clear all the selections and then update the table with only the selected values.
Code:
Private Sub OpenDetail()
    Dim checkedNodes As Collection
    Dim strSql As String
    Dim I As Integer
    Dim nd As Node
    Dim PK As Long
    
    Set checkedNodes = TVW.GetCheckedNodes
    
    strSql = "Update tblLocations set Selected = false"
    CurrentDb.Execute strSql
    strSql = "Update tblItems set Selected = False"
    CurrentDb.Execute strSql
        
    
        
    If checkedNodes.Count > 1 Then
      For I = 1 To checkedNodes.Count
        Debug.Print checkedNodes(I).Key
        Set nd = checkedNodes(I)
        If nd.Tag = "LO" Then
          PK = CLng(Replace(nd.Key, "LO", ""))
          strSql = "Update tblLocations set Selected = True where LocID = " & PK
          Debug.Print strSql
          CurrentDb.Execute strSql, dbFailOnError
        ElseIf nd.Tag = "IT" Then
          PK = CLng(Replace(nd.Key, "IT", ""))
          strSql = "Update tblItems set Selected = True where ItemID = " & PK
          CurrentDb.Execute strSql, dbFailOnError
        End If
      Next I
      DoCmd.OpenForm "frmDetail"
    Else
     DoCmd.OpenForm "frmDetail"
    End If


End Sub

Keep your old Union queries and make a new one where only the selected is true.

If the Checkednodes count is Zero then have the AAA form reinitialize the tree view using the standard query else have it reinitialize with the filtered query.

I would make a second method
Code:
Public Sub InitTreeFiltered()
    Dim nd              As Node
    Dim strQry          As String
    
    '  Debug.Print NodeQuery
    If Me.TVWSort = 1 Then
        strQry = "qryNumericFiltered"
    Else: strQry = "qryAlphaFiltered"
    End If
    
TVW.Initialize Me.XTree.Object, strQry, "LO", True
    If TVW.Nodes.Count > 0 Then
        Set nd = TVW.Nodes(1)
        nd.Selected = True
           Set TVW.TreeView.DropHighlight = nd
        ConfigureSubForms nd
    End If
    
  FormatTree
  FormatNodes
    TVW.expandtree
End Sub

So the calling form can call the initialize method or the initialized filtered method.
 
This demo works but you have to take a branch starting from the a root node.
Select.png

Select2.png


So the below will not currently work, since it does not include the root node.
select3.png


The code could be modified to allow starting a branch at a lower level like you see above. That is not too hard.
But only for the one branch like seen above. If you wanted multiple lower level branches like below is not easy to do.
select4.png
 

Attachments

Users who are viewing this thread

Back
Top Bottom