• Using TreeView Controls in Access (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Using TreeView Controls in Access (Access 2000)

    Author
    Topic
    #377203

    I have a TreeView control in an Access 2000 database, working from Several Related Recordsets.
    It builds and works just fine.

    I want to have a combo box at the top that gives a contract list.
    When a contract is chosen, the Appropriate NODE (and they are all Parent Level) needs to be selected and expanded

    I can get the code to determine if the NODE exists.
    I can get it’s index number, but for the life of me I cannot figure out how to
    a. Get the Program to select that Node Branch
    b. If I could get this far GREAT, but even better would be to expand all it’s child levels.

    Anyone got any ideas?

    I have placed the code I got functional so far below.
    Any help gratefully accepted.

    Private Sub cboContract_AfterUpdate()
    Dim strContract, oNode As Node, fFound As Boolean

    fFound = False

    If Not IsNull(cboContract) Then
    ‘Find the Contract in the list
    strContract = cboContract
    For Each oNode In tvcContracts.Nodes
    If Left(oNode.Text, 8) = “Contract” And Mid(oNode.Text, 12, 6) = strContract Then
    fFound = True
    ‘And this is where I get stuck. I tried the line below but no joy there!
    oNode.Selected = True
    Exit For
    End If
    Next
    End If

    If fFound = False Then
    MsgBox “Cannot find that Contract No in the Tree”
    End If

    End Sub

    The Search on the Node has to determine data from within the Nodes Text property.
    The Data layout of the node is determined by user requirements.

    Thanks (in advance) .

    Viewing 0 reply threads
    Author
    Replies
    • #620667

      OK. I answered my own Post.
      I needed to Focus on the TREEVIEW control first.
      Alternatively I could have created an Object reference to it, and used the Selected property against that, but since I wanted the focus to move anyway
      the method below was just fine.

      Private Sub cboContract_AfterUpdate()
      Dim strContract, oNode As Node, fFound As Boolean

      On Error GoTo SelectTreeItemError

      fFound = False

      If Not IsNull(cboContract) Then
      ‘Find the Contract in the list
      strContract = cboContract
      For Each oNode In tvcContracts.Nodes
      If Left(oNode.Text, 8) = “Contract” And Mid(oNode.Text, 12, 6) = strContract Then
      fFound = True
      ‘And this is where I get stuck. I tried the line below but no joy there!
      tvcContracts.SetFocus
      With tvcContracts.Nodes(oNode.Index)
      .Selected = True
      On Error Resume Next
      .Expanded = True
      .Child.Expanded = True
      .Child.Child.Expanded = True
      On Error GoTo SelectTreeItemError
      End With
      Exit For
      End If
      Next
      End If

      If fFound = False Then
      MsgBox “Cannot find that Contract No in the Tree”
      End If

      Exit Sub

      SelectTreeItemError:
      MsgBox “Contract Cannot be Selected.” & vbLf & Err.Number & vbLf & Err.Description
      Exit Sub

      End Sub

    Viewing 0 reply threads
    Reply To: Using TreeView Controls in Access (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: