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

Criteria in a Query

Status
Not open for further replies.

Jengo

Programmer
Apr 17, 2000
100
US
I have a textbox that has the following value in it:<br><br>&quot;desktop or network or phones&quot;<br><br>How can I have the criteria respond to the &quot;Ands&quot; and not as one big string?&nbsp;&nbsp;I want the query to find the records of any of the words in the textbox, not the entire phrase?
 
NEVER put several things in one field. Why? You can't get anything meaning out of it without a PhD in VBA.<br><br>I think you need a function.<br><br>But it will only work if you data is consistant.<br>Are there always 3 items like "Desktop", "Network", "Phones"<br>Are they always separated by the word "OR"<br>-----------------------<br>Public Function AndJunkData(Junk)<br>    'Next time don't let any one put 3 items in one field<br>    Dim FirstAnd As String, SecondAnd As String, ThirdAnd As String<br>    Dim FindFirstOR, SecondOR As Integer<br>    Dim AllUpperCase As String<br>    AllUpperCase = UCase(Junk)<br>    FindFirstOR = InStr(1, AllUpperCase, " OR ")<br>    SecondOR = InStr(FindFirstOR + 1, AllUpperCase, " OR ")<br>    FirstAnd = Left(Junk, FindFirstOR - 1)<br>    ThirdAnd = Right(Junk, Len(Junk) - SecondOR - 3)<br>    SecondAnd = Mid(Junk, FindFirstOR + 4, Len(Junk) - Len(ThirdAnd) - Len(FirstAnd) - 8)<br>    AndJunkData = FirstAnd & " AND " & SecondAnd & " AND " & ThirdAnd<br>End Function<br>-----------------------------<br>If one record in a database has more than one relation like your 3, network desktop and phone then either create another table or create 3 fields.<br><br><br><br>
 
If you are attempting to query on more then one criteria another option to consider is a multiselect list box there have been numerous postings throughtout this forum on utilizing a list box for multiselect. Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top