Consulting

Results 1 to 4 of 4

Thread: Checking field entry

  1. #1

    Checking field entry

    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.

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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

  3. #3
    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

  4. #4
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    [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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •