Hi Guys,
Quick one.
Usually the IF statement are with an equal to sign. How do I write it if I need to check if the field CONTAINS something.
Means, if a field contains this word, then do this.
Thanks for your help in advance.
Hi Guys,
Quick one.
Usually the IF statement are with an equal to sign. How do I write it if I need to check if the field CONTAINS something.
Means, if a field contains this word, then do this.
Thanks for your help in advance.
You would use the "Instr" Function. Returns > 0 if the needle is found in the haystack.
[VBA]
If Instr("haystack", "needle") > 0 Then ' found it!
' code here
Else ' not found
' code here
End If
[/VBA]
Regards,
JP
Read the FAQ
Getting free help on the web
My website
Please use [vba][/vba] tags when posting code
Thanks JP,
I am a little confused as to how to use the code.
I have an IF statement to check whether an email address, say abc@xyz.com, is in the to field. I want the condition to be true also even if
any other mail address is written along with it.
My code looks like the below:
If .To = abc@xyz.com Then
[VBA]If Instr(.To , "abc@xyz.com") > 0 Then ' found it!
' code here
Else ' not found
' code here
End If [/VBA]
-----------------------------------------
The more you learn about something the more you know you have much to learn.