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

Running total field when a sting exists? 1

Status
Not open for further replies.

butkus

MIS
Sep 4, 2001
114
US
I want to count the number of instances were a sting of text appears. The word I seek can exist in any number of ways, but the field is not a memo field. Can this be done?
 
I tested it and it seems to work (somewhat).
The field I want to evaluate can contain anything (its free form). I want to search for any instance of "condom" (this database is for a clinic providing services to teen mothers). Some of the data looks like this:

condom
condoms
pill & condom
pill & condoms
depo & condom
condom & depo

you get the idea.

I need something that will catch and count every instance of "condom".
 
The afore-mentioned running total solution should do this, (though I think the example might be the wrong way around). Just switch the components of InStr around.

Alternatively, you can use a variable:

Try:
Code:
WhilePrintingRecords;
NumberVar Condom;

If InStr({Contraception},'condom') > 0
Then Condom := Condom + 1
Else Condom;
and
Code:
WhilePrintingRecords;
NumberVar Condom;
where you want the total displayed.

Remember to reset the Condom counter to 0 in the group header, if you need it to reset at all.

Naith
 
It just clicked that you said the field was free form; so you might need to incorporate case checks, so that you can catch instances like "Condom" and "CONDOM".

InStr(lowercase({Contraception}),'condom') > 0

If you're worried about catching typoes too, read up on the Soundex function. It's a reasonable typo catcher, but also takes a reasonable bite out of performance.

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top