• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Separating an indeterminate number of words and searching on them

I have a form with a keyword search box (there are other things that are included in the search on the form ... checkboxes and such).

The keyword search box instructs users to enter one or more search terms separated by commas.  How can I (in code) take apart the search string (without knowing really how long it is)... at the comma, remove the spaces, and search a table ("MyTable") for each term? (I have a radio button that allows users to select "AND" or "OR" and I'll incorporate that info into the query i build in code).

Thanks for your help.
0
epuglise
Asked:
epuglise
  • 4
  • 4
1 Solution
 
RunriggerCommented:
Declare and array string


Dim sArray() as String

Split the string the users enters by comma;

sArray = Split(userstring,",")

For n = 1 to Ubound(sArray)

sSearch = sArray(n)
Perform serach hare

next n
0
 
epugliseAuthor Commented:
ok i had no idea there was a "split" function!  Great testing this now!

0
 
RunriggerCommented:
you can even join them back together;

sOtherString = Join(sArray," AND ")

sOtherString = Join(sArray," OR ")
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
epugliseAuthor Commented:
OK that did it.  Just one thing... I had to change one line:

for n = 0 to ubound(sArray)

in order to get the first search term and I incorporated a "trim" function to get rid of the spaces.

Great!! Thanks for the new function!
0
 
epugliseAuthor Commented:
Excellent... thanks for the And / Or tip!  "Bonus" kudos :)
0
 
RunriggerCommented:
Sorry about that, I sometimes  forget that arrays are zero based!

Thanks for the grading
0
 
epugliseAuthor Commented:
No problem... what a tidy little function Split is.  Saved me a bunch of brain cells... and I liked the method of gluing stuff back together so it all worked out ... i just wanted to post the minor correction for future users :)
0
 
RunriggerCommented:
the function is great for doing a search and replace;

Function SearchAndReplace(sString as string,sSearchValue as string,sReplaceValue as String) as String
SearchAndReplace = Join(Split(sString,sSearchValue),sReplaceValue)
End Function
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now