Solved

Separating an indeterminate number of words and searching on them

Posted on 2011-02-10
8
271 Views
Last Modified: 2012-05-11
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
Comment
Question by:epuglise
  • 4
  • 4
8 Comments
 
LVL 11

Accepted Solution

by:
Runrigger earned 500 total points
Comment Utility
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
 

Author Comment

by:epuglise
Comment Utility
ok i had no idea there was a "split" function!  Great testing this now!

0
 
LVL 11

Expert Comment

by:Runrigger
Comment Utility
you can even join them back together;

sOtherString = Join(sArray," AND ")

sOtherString = Join(sArray," OR ")
0
 

Author Comment

by:epuglise
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:epuglise
Comment Utility
Excellent... thanks for the And / Or tip!  "Bonus" kudos :)
0
 
LVL 11

Expert Comment

by:Runrigger
Comment Utility
Sorry about that, I sometimes  forget that arrays are zero based!

Thanks for the grading
0
 

Author Comment

by:epuglise
Comment Utility
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
 
LVL 11

Expert Comment

by:Runrigger
Comment Utility
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now