Looking for words in a string

George Too

Registered User.
Local time
Today, 17:12
Joined
Aug 12, 2002
Messages
198
OK, here we go again.

How do I make my code look for a word within a string a then do something. For example, I have the string "This is a test for 6th grade." and "This is a demo for 7th grade." I want the code to look for the words 'test' and 'demo' and then run the appropriate code.

Thanks.
George
 
If Instr(1, YourMessage, "demo") Then

(do your event)

ElseIf Instr(1, YourMessage, "test" Then

(do your event)

Else

(a fallback event, if necessary)

End If
 
Thanks Mile-O-Phile, that works. Now how do I build a Select Case using 'Instr(1, YourMessage, "demo")' ? I have tried but I keep getting type mismatch errors.

Here is the code that I'm using:

Dim Brand as String
Brand = Me.cmbBrand
Select Case Me.cmbBrand
Case Me.cmbBrand Is InStr(1, Brand, "colombian")
'do something
Case Me.cmbBrand Is InStr(1, Brand, "special roast")
'do something
Case Me.cmbBrand Is InStr(1, Brand, "classic roast")
'do something
Case Me.cmbBrand Is InStr(1, Brand, "latte vanilla")
'do something
End Select

Thanks,
George
 
George,

Sorry, a case statement will not work that way.

You'll either have to populate an array with your words or
loop through a recordset.

Wayne
 
I figure it would not. Would an array be more efficient than using a whole bunch of IF statements? I have about 30 of those.
 
George,

An array would definitely be more efficient,
but if you build it from a recordset than
why not just use the recordset?

Wayne
 
Well, I think I'm sticking to the IF statements. This array thing sound a bit complicated for my dateline.

Thanks Wayne.

George
 

Users who are viewing this thread

Back
Top Bottom