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

Problems with "CreateAutosearchCriteria"

edited June 2003 in End User
Hi!

I'm trying to "filter" a report using AutoSearch criteria.
I have been working with some examples, and it works fine with designed-time
reports.

For example, if I edit a report (design-time) witha "query sql sentence",
the folowing code works fine!

procedure TForm1.FormCreate(Sender: TObject);
begin
ppreport1.CreateAutosearchCriteria( 'customers' , 'NAME' , soEqual ,
'Mark' , false);
ppReport1.ShowAutoSearchDialog := false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ppReport1.Reset;
ppReport1.Print;
end;

But if I load a report template, containing data form the same table, the
report is blank.
For example:

procedure TForm1.FormCreate(Sender: TObject);
begin
ppReport1.ShowAutoSearchDialog := false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ppreport1.template.filename := 'c:\test.rtm';
ppreport1.template.loadfromfile;
ppreport1.CreateAutosearchCriteria( 'customers' , 'NAME' , soEqual ,
'Mark' , false);
ppReport1.Print;
end;

Is it possible to create AutoSearch fields for report templates?

Thanks!

Comments

  • edited June 2003
    Yes, you should be able to call CreateAutosearchCriteria in order to create
    a search criteria object on the dataview which is an autosearch criteria. Is
    customers the name of the dataview in the template report? Is Name a field
    in this dataview? Does the report template have this dataview assigned to be
    its data? Can you load this report template at rutime into the report
    designer and then create a autosearch criteria visually through the query
    designer?


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    Hi, Jim!

    I think I have found the problem!

    If the template slq references to 2 tables (for example, "customers" and
    "orders"), I only can create search criterias for the first one!

    For example, if I call:

    ppreport1.CreateAutosearchCriteria( 'customers' , 'CustNo' , soEqual ,
    '1221' , false);
    ppreport1.CreateAutosearchCriteria( 'orders' , 'OrderNo' , soEqual ,
    '1005' , false);

    ...then it only filters "CustNo = 1221", but ignores the "OrderNo = 1005".

    Is it normal?
    Please, help! I love programming and discovering RBuilder options, but...
    ;-)

    Thanks!




  • edited June 2003
    Are these tables linked master detail? I think in an older version of RB
    5.5-6 somewhere that there was a limitation on the second joined table in a
    detail dataview which it didn't support search criteria when it generated
    the SQL. CAn you test with RB 7.02? If you ctrl-mouse click of the
    dataviews, what does the magic SQL look like? Does the criteria get added
    when you view the SQL submitted to the database server after you enter the
    values in the autosearch dialog and rerun the report? You can view the SQL
    via the RB interface by extracting the SQL object and referencing the
    TdaSQL.MagicSQLText property. Here is an example on getting the SQL object
    for a dataview in the report. You can get eth sql object in the
    Report.BeforePrint event because the Report.BeforePrint should fire after
    the magic SQL is generated and the report is ready to start generating
    pages.

    http://www.digital-metaphors.com/tips/ExtractSQLObject.zip

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    Hi, Jim!

    I have RBuilder Pro 7.02 and Delphi 7 Pro.

    I know I can see the SQL Object and the MagicSQL text, and it works with one
    of the references tables, but not with other.

    I have sent you an e-Mail with an example using "dbdemos" customer table,
    and a
    Try to add another SearchCriteria for a field of the table "orders" and load
    the report template, and you'll se it is ignored.

    Thanks!
  • edited June 2003
    Handled via email.

    Summary:

    When creating search criteria in DADE, use the dataview's name, not
    necessarily the name of the table that is joined in the dataview for the
    field from which the criteria is based.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.