Subject Re: Adding search criteria to WHERE clause and more..not working as expected.
Author mspencewasunavailable
--- In IBObjects@yahoogroups.com, "Adrian Wreyford" <wreymed@...>
wrote:
>
> Well I asked a similar question a week ago, and no answer. But
today I
> stumbled on something I think is the answer, but cannot get ti to
work.
>
>
>
> I want to assign Search criteria to a report Query, then add a
between dates
> clause for Date OF Birth field to the where clause, and then run
the report.
>
>
>
> I thought the following would do, but the add items, doesn't
appear to add
> the item:
>
> I put the dataset into prepare state; must be missing something
here?
>
>

Declare an OnPrepareSQL event handler:

procedure <suitable object>.RestrictToDOB(Sender: TObject);
begin
(Sender as TIBODataset).SQLWhereItems.Add('ANIMAL.ANIMALDOB
BETWEEN ''' +
DateToStr(DTPBeg.Date) + ''' AND ''' + DateToStr(DTPEnd.Date)
+ ''' ');
end;

Then assign it:

IBOQuery1.OnPrepareSQL := <instance of the suitable
object>.RestrictToDOB;


I don't think you need to do this Prepare any more:
>
> IBOQuery1.Prepare;
>

Do this, though (I think the OnPrepareSql event gets called as a
result of this).
> IBOQuery1.AssignSQLWithSearch(IB_Query1);
> IBOQuery1.Open;
>

Michael D. Spence
Mockingbird Data Systems, Inc.