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!

Searching for Multiple Keywords in a Memo Field

Status
Not open for further replies.

Dond12

Technical User
May 3, 2001
57
US
I have a report that allows me to enter multiple keywords and then searches for occurrences of them in a memo field. Here is the language I use in the selection criteria:

numbervar counter ;
stringvar holder ;
holder := "" ;
counter := 0 ;
for counter := 1 to count({?Search Value}) step 1 do
holder := {?Search Value}[counter] ;
holder in {Filename.memofield}

This works great. If I enter three keywords, the report returns all of the records in which EITHER the first word, OR the second word, OR the third word occurs.

Here's my problem: I would like to insert a parameter that allows the user to specify that he or she would like the report to consider ANY term or ALL OF THE TERMS.

In other words, what is the language if you want the report to return records in which the first keyword AND the second keyword AND the third keyword ALL APPEAR?

Obviously, I can set up a finite number of variables (e.g., Text 1 = parameter[1] and Text 2 = parameter[2] and so on), but this limits me to however many variables I create ahead of time. Also, it seems pretty inelegant to me.

Is there a better way? I am using Crystal Reports 9.2.
 
This means that you'll have to allow for AND or OR in the record selection formula.

One means might be to create formulas to use in the record selection formula:


@formula1
If ubound({parm}) > 0
and
{?parm}[1] <> "None" then
{?parm}[1]
else
""

@formula2
If ubound({parm}) > 1
and
{?parm}[2] <> "None" then
{?parm}[2]
else
""
etc.

Then the record selction formula could contain:

(
if @formula1 <> "" then
@formula1 in {table.field}
)
and
(
if @formula2 <> "" then
@formula2 in {table.field}
)
etc.

Should work.

-k
 
Thanks. I appreciate it. Doesn't this solution, however, force me to define precisely how many keywords I am going to link?
 
Is there a way I can write the query so that I don't have to specify ahead of time how many (or the upper limit) of the parameters I'm looking for? The solution proposed is fairly similar to what I've already done (i.e., defined seven variables, each corresponding to one keyword -- v1 = {?para}[1] ; v2 = {?para}[2] ; and so on up to v7={?para}[7]).

This seems kind of clumsy to me (even though it works -- I set v7, for example, to equal {?para}[7], unless there is no {?para}[7], in which case I just set v7 to equal {?para}[1]. No harm, no foul.

Still, it bothers me that I have to do this, instead of just creating as many variables as I actually need, and no more.

As you can probably tell, I'm no programmer -- so there is probably some rudimentary programming rule I am not applying here. My apologies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top