find and color text red in a richtextbox each time the find button is clicked

Private Sub cmdFind_Click()
Dim NewStart As Integer
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

Open in new window


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 ?
isnoend2001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
change:
Dim Start As Integer

Open in new window


for
Static Start As Integer

Open in new window


and just before the "end with", add
Start += Length

Open in new window

0
isnoend2001Author Commented:
Thanks but it still only finds the first occurrence .
Dim str As String
Static Start As Integer
Dim Length As Integer
str = Me.txtFind
Length = Len(str)
Start = rtfBills.Find(str, , , rtfWholeWord)

With rtfBills
.SelStart = Start
.SelLength = Length
.SelColor = vbRed
Start = Start + Length
End With

Open in new window

0
Éric MoreauSenior .Net ConsultantCommented:
You also need to use a different Find overloads:
Start = rtfBills.Find(str, Start, rtfWholeWord)

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

isnoend2001Author Commented:
Start = rtfBills.Find(str, Start, rtfWholeWord) where to put that ?
0
Éric MoreauSenior .Net ConsultantCommented:
replace line 6 of your last example
0
isnoend2001Author Commented:
That produces an error "Invalid property value"
start is -1
0
Éric MoreauSenior .Net ConsultantCommented:
I just saw that you are still using VB6? That should work better for you:

Start = rtfBills.Find(str, Start, , rtfWholeWord)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isnoend2001Author Commented:
txtFind contents = HARBOR
rtfBills contents:
6/13/2003 VILLAGE SUPPLIES LTD   ALSIP  IL -24.61
6/17/2003 LEWIS & LEWIS ENTERPR   VENTURA CA -96.09
6/27/2003 HARBOR FREIGHT TOOLS   805 388-2000    CA -58.77
7/7/2003 BUY.COM   WWW.BUY.COM CA -27.84
7/11/2003 THE NEXTREND INC   IRVINE  CA -18.74
7/15/2003 AMAZON.COM  *PAYMENTS   800-201-7575 WA -11.23
7/20/2003 AMAZON.COM  *PAYMENTS   800-201-7575    WA -13.99
7/21/2003 HARBOR FREIGHT TOOLS   805 388-2000    CA -58.77
8/5/2003 AMAZON.COM  *PAYMENTS   800-201-7575    WA -14.48
8/12/2003 BUY.COM   WWW.BUY.COM CA -26.34
8/13/2003 HARBOR FREIGHT TOOLS   805 388-2000    CA -61.81
8/28/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -83.13
8/28/2003 ECAMPUS COM   TEL8595145200 KY -49.83
9/4/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -108.74
10/13/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -56.87
11/7/2003 BUY.COM   WWW.BUY.COM CA -29.17
11/13/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -23.89
12/15/2003 AMAZON.COM  *SUPERSTOR   AMAZON.COM WA -30.59
0
isnoend2001Author Commented:
Thanks Éric Moreau that works
0
isnoend2001Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for isnoend2001's comment #a40708332

for the following reason:

Thanks Éric Moreau
0
Éric MoreauSenior .Net ConsultantCommented:
Why don't you accept my comment as the answer?
0
isnoend2001Author Commented:
Thanks thought i did
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.