Question to Gurus

aleb

Registered User.
Local time
Today, 23:14
Joined
Jun 25, 2003
Messages
296
Dear Gurus,

Where do I need to post my message regarding the search in Treeview as I desperately need a solution ?

Your help is really appreciated
P.S. I have figured out how to subsequently find search item on the tree, but still can't figure out how to in "one shot" expand all the nodes where the search item is found.
Please have a look at the code or advise where to post the message

============================================
Public Sub mTvw_KeyUp(KeyCode As Integer, ByVal Shift As Integer)
Dim strSeek As String

If IsLoaded(cNamefrm) = True Then
isFind = False
With Forms(cNamefrm)
strSeek = .Controls(cNameField)
End With
DoCmd.Close acForm, cNamefrm
DoEvents
DoCmd.Hourglass True
Call SeekInTree(mTvw.SelectedItem, strSeek)
DoCmd.Hourglass False
End If
End Sub

Public Sub mTvw_KeyPress(KeyAscii As Integer)
If KeyAscii <= 31 Then Exit Sub
DoCmd.OpenForm cNamefrm, , , , acFormEdit, acDialog, Chr(KeyAscii)
End Sub

Private Function SeekInTree(startnode As Node, strFind As String)

On Error GoTo SeekInTree_ERR
If isFind = False Then
If startnode.Children > 0 Then
If InStr(1, startnode.Text, strFind) > 0 Then
startnode.Selected = True
isFind = True
Exit Function
Else
Call SeekInTree(startnode.Child, strFind)
If startnode.LastSibling.Key <> startnode.Key And isFind = False Then
Call SeekInTree(startnode.Next, strFind)
End If
End If
Else
If InStr(1, startnode.Text, strFind) > 0 Then
startnode.Selected = True
isFind = True
Exit Function
Else
If startnode.LastSibling.Key <> startnode.Key And isFind = False Then
Call SeekInTree(startnode.Next, strFind)
Else
Exit Function
End If
End If
End If
End If

SeekInTree_EXIT:
Exit Function

SeekInTree_ERR:
Select Case Err.Number
Case Else
MsgBox Err.Description & "(" & Err.Number & ") in module SeekInTree"
Resume SeekInTree_EXIT
End Select
End Function
 
No idea but it makes things a hell of a lot easier to read if you use the [code] tags around your code:

Code:
Public Sub mTvw_KeyUp(KeyCode As Integer, ByVal Shift As Integer)
Dim strSeek As String

    If IsLoaded(cNamefrm) = True Then
        isFind = False
        With Forms(cNamefrm)
            strSeek = .Controls(cNameField)
        End With
        DoCmd.Close acForm, cNamefrm
        DoEvents
        DoCmd.Hourglass True
        Call SeekInTree(mTvw.SelectedItem, strSeek)
        DoCmd.Hourglass False
    End If
End Sub

Public Sub mTvw_KeyPress(KeyAscii As Integer)
    If KeyAscii <= 31 Then Exit Sub
    DoCmd.OpenForm cNamefrm, , , , acFormEdit, acDialog, Chr(KeyAscii)
End Sub

Private Function SeekInTree(startnode As Node, strFind As String)

    On Error GoTo SeekInTree_ERR
    
    If isFind = False Then
        If startnode.Children > 0 Then
            If InStr(1, startnode.Text, strFind) > 0 Then
                startnode.Selected = True
                isFind = True
                Exit Function
            Else
                Call SeekInTree(startnode.Child, strFind)
                If startnode.LastSibling.Key <> startnode.Key And isFind = False Then
                    Call SeekInTree(startnode.Next, strFind)
                    End If
                    End If
                Else
                    If InStr(1, startnode.Text, strFind) > 0 Then
                        startnode.Selected = True
                        isFind = True
                        Exit Function
                    Else
                        If startnode.LastSibling.Key <> startnode.Key And isFind = False Then
                            Call SeekInTree(startnode.Next, strFind)
                        Else
                            Exit Function
                        End If
                    End If
                End If
            End If
        End If
    End If
    
SeekInTree_EXIT:
    Exit Function

SeekInTree_ERR:
    Select Case Err.Number
        Case Else
            MsgBox Err.Description & "(" & Err.Number & ") in module SeekInTree"
            Resume SeekInTree_EXIT
    End Select
End Function

You were also missing two End If statements in that code - I added them.



Now, what are you searching?

Is it the value of a node?
 
Yes, I am looking a value in the tree, and I need the function to look through the whole tree and expand the tree everywhere the value is found.
 
How's this for you?

Code:
Dim strCriteria As String

strCriteria = InputBox("Enter search criteria", "Test")

For Each Node In ctlTree.Nodes
    If Node.Text = strCriteria Then
        Node.Expanded = True
    End If
Next
 
Mile ... you know ... I am pretty dumb when it comes to the VBA
Everything to the "Module" tab is quite easy ... I suspect there is something wrong with declaration of variables. While compiling the module Access doesn't recognize what you have wrote. May be it would be better if I send you the DB itself or all the codes in "txt" file. I really don't want to be forthputting, so if it gives you some trouble I would look for help somewhere else.
Let me know.

Regards, Alexei
 
No probs - I've sent you a PM.
 

Users who are viewing this thread

Back
Top Bottom