[RESOLVED] find and color text red in a richtextbox each time the find button is clicked
Code:
Private Sub cmdFind_Click()
Dim str As String
Dim Start As Integer
Dim Length As Integer
str = txtFind
Length = Len(str)
Start = rtfBills.Find(str, , , rtfWholeWord)
With rtfBills
.SelStart = Start
.SelLength = Length
.SelColor = vbRed
End With
This works fine for finding the first occurrence of a word, but need it modified to find the next occurrence of the word with each button click
How to do this ?
Re: [RESOLVED] find and color text red in a richtextbox each time the find button is
Code:
Private Sub cmdFind_Click()
Dim strFind As String
strFind = txtFind
With rtfBills
If LenB(.SelText) Then .SelStart = .SelStart + .SelLength
On Error GoTo 1
.SelStart = rtfBills.Find(strFind, .SelStart, , rtfWholeWord)
On Error GoTo 0
.SelLength = Len(strFind)
.SelColor = vbRed
End With
Exit Sub
1 If MsgBox("End of search scope has been reached. Continue from the beginning?", vbYesNo Or vbQuestion) = vbYes Then
rtfBills.SelStart = 0&
Resume
End If
End Sub
Re: [RESOLVED] find and color text red in a richtextbox each time the find button is
Thanks Bonnie West Idid this:
Code:
Private Sub cmdFind_Click()
Dim NewStart As Integer
Dim str As String
Static Start As Integer
Dim Length As Integer
str = Me.txtFind
Length = Len(str)
Start = rtfBills.Find(str, Start, , rtfWholeWord)
If Start <> -1 Then
With rtfBills
.SelStart = Start
.SelLength = Length
.SelColor = vbRed
miNuSearchResults = miNuSearchResults + 1' for reset
Start = Start + Length
End With
Else
MsgBox "Not found"
End If
End Sub