INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA finding multiple words in a text box

VBA finding multiple words in a text box

(OP)
On a Access 2010 form I have a drop down control to select a job discrption. On the "after update event", I check the underlining text conrol for a value. If it is there, I perform some work. This is the VB code for that check.

If InStr(Me.Job_Catagory, "Instructor") Then (this works fine)

So, now I need to expnd this to check for any of three words..Instructor or Admin or Lead. I have tried google and other sources to see how to look for more than one word in a text box and have come up empty. Is there some combination of "OR" I could use with the IF and InStr statements?

Can anyone help with this.

Thanks,

RE: VBA finding multiple words in a text box

Hi,

Did you try If x Or y Or z Then

...naturally substituting an InStr() for each?

RE: VBA finding multiple words in a text box

puforee,

I'd also lowercase everything (you don't know whether they capitalised or not):

CODE -->

Dim strJob as String

strJob  = lcase(Me.Job_Catagory)

If (InStr(strJob, "instructor") > 0 Or _
    InStr(strJob, "admin") > 0 Or _
    InStr(strJob, "lead") > 0) Then
       'Do some stuff
End If 

Or...

CODE

If (InStr(strJob, "instructor") > 0) Then
   'Do some instructor stuff     
Else
   If (InStr(strJob, "admin") > 0) Then
      'Do some admin stuff
   Else
      If (InStr(strJob, "lead") > 0) Then 
         'Do some lead stuff
      End if
   End if 
End If 

ATB,

Darrylle

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.

RE: VBA finding multiple words in a text box

I would put a value in a hidden dropdown column
and use this code

CODE

Select Case Me.Job_Catagory
Case 1
'Do some instructor stuff
Case 2
'Do some admin stuff
end select

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close