Results 1 to 2 of 2
  1. #1
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Using TreeView Controls in Access (Access 2000)

    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) .
    Andrew

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Using TreeView Controls in Access (Access 2000)

    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
    Andrew

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •