How To…Apply Single AutoSearch to Multiple Queries

Question

How can I define a single autosearch parameter and apply it to multiple queries?”

Solution

Implement the Report.BeforeOpenDataPipelines event and use SQLBuilder to apply the AutoSearch value to additional queries.

Download:  ApplyAutoSearchValueTo2ndQuery.zip

Sample RAP code:

procedure ReportBeforeOpenDataPipelines;
var
  lSQLBuilder: TdaSQLBuilder;
begin

 {create SQLBuilder - pass the Customer2 datapipeline to the constructor}
 lSQLBuilder := TdaSQLBuilder.Create(Customer2);
 
 if (Report.AutoSearchFields[0].ShowAllValues) then
 
   {clear existing search criteria}
   lSQLBuilder.SearchCriteria.Clear  
   
 else if (lSQLBuilder.SearchCriteria.Count = 0) then
 
   {add new search criteria with the autosearch field value}
  lSQLBuilder.SearchCriteria.Add('customer', 'custno', 'Between', Report.AutoSearchFields[0].SearchExpression)
 
 else {update existing search criteria with the autosearch field value}
   lSQLBuilder.SearchCriteria[0].Value := Report.AutoSearchFields[0].SearchExpression;
 
   
 lSQLBuilder.ApplyUpdates;
 lSQLBuilder.Free;
 

end;