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

VBA finding multiple words in a text box 1

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
0
0
US
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,
 
Hi,

Did you try If x Or y Or z Then

...naturally substituting an InStr() for each?
 
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.
 
I would put a value in a hidden dropdown column
and use this code
Code:
Select Case Me.Job_Catagory
[indent]Case 1[/indent]
[indent][/indent][indent][/indent]'Do some instructor stuff
[indent]Case 2[/indent]
[indent][/indent][indent][/indent]'Do some admin stuff
[indent][/indent]end select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top