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

*LIKE * sytntax with an IF statement

Status
Not open for further replies.

ruthcali

Programmer
Apr 27, 2000
470
US
For an IF Statement, what is the syntax for *like*

I've tried so many combinations of:

IF txtField like '*" & Me.stringField & "*'
IF txtField like " & "'" & "*" & me.stringField & "*" & "'"
IF txtField like " & "* & me.stringField & *"

But nothing works!!
(StringField is a string)

Thanks
 
If you're creating a conditional statement based on a textfield, you probably want to do something like:

IF instr(1,txtfield,me.stringfield,vbTextCompare) then

If you're building a query, don't use "IF" use "WHERE"
 
You could use Instr for this:

if instr(1, txtField, me.stringField, 1) <> 0 then

 
Thanks to both of you for writing.

I can't use Instr because of the following:

My string being searched is a memo field.

My string expression sought is all the employee names separated by commas:
&quot;Jones, Anderson, Smith, Lake, Johnson&quot;

So if Mr.Smith's name shows up anywhere in the memo field, the IF statement will be true.

So i thought i should use *LIKE*, but i can't get the syntax straight.

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top