LOCAL lnWordCount, lnI, lcWords, lcFiltCond, lcFieldName IF thisform.opgFields.Visible AND thisform.opgFields.Value <> 0 AND NOT EMPTY(ALLTRIM(thisform.txtKeywords.Value)) * Put each keyword entered into an array lcWords = UPPER(ALLTRIM(thisform.txtKeywords.Value)) lnWordCount = OCCURS(' ',lcWords)+1 DIMENSION laWords[lnWordCount] IF lnWordCount = 1 laWords[1] = lcWords ELSE FOR lnI = 1 TO lnWordCount IF lnI = 1 laWords[lnI] = LEFT(lcWords,AT(' ',lcWords)-1) ELSE laWords[lnI] = STREXTRACT(lcWords,' ',' ',lnI-1,2) ENDIF ENDFOR ENDIF * Figure out which field we're filtering on lcFieldName = thisform.aFields[thisform.opgFields.Value] * Build the filter condition lcFiltCond = '' FOR lnI = 1 TO lnWordCount IF thisform.opgKeywords.Value = 1 && All keywords IF lnI > 1 lcFiltCond = lcFiltCond+" and " ENDIF ELSE && Any keyword IF lnI > 1 lcFiltCond = lcFiltCond+" or " ENDIF ENDIF DO CASE CASE TYPE(lcFieldName) = "C" lcFiltCond = lcFiltCond+"["+laWords[lni]+"] $ UPPER("+lcFieldName+")" CASE TYPE(lcFieldName) = "N" lcFiltCond = lcFiltCond++laWords[lni]+" = "+lcFieldName+" OR "+lcFieldName+" = "+laWords[lni] ENDCASE ENDFOR SET FILTER TO &lcFiltCond COUNT TO lnI WAIT WINDOW NOWAIT TRANSFORM(lnI)+" records met your filter criteria" TIMEOUT 5 GOTO TOP RETURN .T. ELSE RETURN .F. ENDIF