Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Report without AutoSearch

edited February 2003 in General
Hello,

I'm trying to use a variable in an SQL statement.

1. In the Calc tab of the Report Designer, I declare a variable:
var
FromDate: TDateTime;

2. In the GlobalOnCreate event, I put the following code:
procedure GlobalOnCreate;
begin
FromDate := CurrentDate;
end;

3. I want to use FromDate as a search criteria for my report, so in the
Query Designer, Search tab I have:

MYTABLE.MYSTARTDATE = FromDate

4. This results in an Invalid SQL Statement error message.

What is the proper way to do this, keeping in mind that the report is to
run without end-user input, ie without using AutoSearch?

Cheers,
Daniel

Comments

  • edited February 2003

    Try this....

    1. Define the search condition as AutoSearch

    2. Use the Report.BeforeAutoSearchDialogCreate event to set

    Report.ShowAutoSearchDialog := False;

    3. Use the Report.OnGetAutoSearchFieldValues event to programmatically set
    the search criteria:

    if (Report.AutoSearchFields[0].FieldName = 'myStartDate') then
    Report.AutoSearchFields[0].SearchExpression := DateToStr(CurrentDate);


    Note: These events are not fired when selecting the Preview tab in the
    report designer. They fired when you call Print to preview or print, etc..



    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited February 2003
    Thank you, Nard. Worked like a charm.

    Cheers,
    Daniel

This discussion has been closed.