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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continue to search from last found problem 1

Status
Not open for further replies.

cuok

Programmer
Dec 24, 2001
201
Hi friends!
I'm using this routine to search text typed into 'txtgetmed' TextBox and maybe appear in 'txtDetail' TextBox.
its works fine for first search.
What i need is an idea how to continue the search in 'txtDetail' from this 'found'.

here the code:
Code:
[B]
Private Sub GoSearch_Click()
 Dim strSearch  As String, intWhere As Integer
    Dim ctlTextToSearch As Variant
 
   
    With Me!txtDetail
           strSearch = txtgetmed

    intWhere = InStr(txtDetail, strSearch)
        If intWhere Then
            .SetFocus
            .SelStart = intWhere - 1
            .SelLength = Len(strSearch)
        Else MsgBox txtgetmed & "  Not Found"
     
        End If
      End With

End Sub
[/B]

Thanks in advance
CUOK

 
Declare a module-level variable intStart. In the txtDetail_AfterUpdate event, set intStart to 0. Modify GoSearch_Click to:
Code:
        intWhere = InStr(intStart, txtDetail, strSearch)
        If intWhere Then
            .SetFocus
            .SelStart = intWhere - 1
            .SelLength = Len(strSearch)
            intStart = intWhere + Len(strSearch)
        Else 
            MsgBox txtgetmed & "  Not Found"
        End If
You may also need to set intStart to 0 in Form_Current and/or other places where it makes sense to start searching from the beginning again.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thank u RickSpr!
its works perfectly!!!
CUOK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top