How to stop report on no data

hsmhsm
edited 2:03AM in FastReport 4.0
I am trying to show a message and stop a report if there is no data to show.

In the report I can see, and use fields from the TfxDBDataset (called frxDBDatasetNextStepsByDept).
I have the OBP event as follows
procedure Page1OnBeforePrint(Sender: TfrxComponent);
begin
    if frxDBDatasetNextStepsByDept.RecordCount = 0 then  //<--this uses the TfxDBDataset 
  begin
    ShowMessage('No data is available for this report');
    engine.stopreport;                                                                   
  end;  
end;

However I get an undefined identifier error on frxDBDatasetNextStepsByDept. The same happens if I use the TClientDataSet that it is connected to or if I put in the form name as well
ie Frm_NextStepsReports.frxDBDatasetNextStepsByDept

The report uses the following chain of components to get its data from a SQLite3 database.
SQLite Database -> DISQlite3UniDirQuery (called QryNextStepsByDept) -> TDataSetProvider (called dspNextStepsByDept) ->TClientDataSet (called cdsNextStepsByDept) ->TfxDBDataset (called frxDBDatasetNextStepsByDept) ->TfrxReport . They are on a delphi form called Frm_NextStepsReports

What is the correct syntax to do it?
Is there even an 'OnNoData' event for a report hidden away somewhere [img]style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> Howard[/img]

Comments

  • gpigpi
    edited 2:03AM
    Modified script for 52.fr3 from FRDemo
    procedure Button1OnClick(Sender: TfrxComponent);
    begin
      BDEQuery1.Close;
      BDEQuery1.ParamByName('p1').Value := StrToInt(Edit1.Text);
      BDEQuery1.Open;                                  
    end;
    
    procedure Page1OnBeforePrint(Sender: TfrxComponent);
    begin
       // if BDEQuery1.RecordCount = 0 then  //<--this uses the internal dataset                                         
        if Report.GetDataset('Internal query').RecordCount = 0 then //<--this uses the TfxDBDataset
          begin
            ShowMessage('No data is available for this report');
            engine.stopreport;
          end;   
    end;
    
    begin
    
    end.
    
  • hsmhsm
    edited 2:03AM
    gpi wrote: »
    Modified script for 52.fr3 from FRDemo
    procedure Button1OnClick(Sender: TfrxComponent);
    begin
      BDEQuery1.Close;
      BDEQuery1.ParamByName('p1').Value := StrToInt(Edit1.Text);
      BDEQuery1.Open;                                  
    end;
    
    procedure Page1OnBeforePrint(Sender: TfrxComponent);
    begin
       // if BDEQuery1.RecordCount = 0 then  //<--this uses the internal dataset                                         
        if Report.GetDataset('Internal query').RecordCount = 0 then //<--this uses the TfxDBDataset
          begin
            ShowMessage('No data is available for this report');
            engine.stopreport;
          end;   
    end;
    
    begin
    
    end.
    

    Thank you, that seemed to work to display the message (using the '<--this uses the TfxDBDataset' line). However the report is still left open with just a grey background.

    Is it possible to also close the report and return to my program - without clicking the close button.
  • gpigpi
    edited 2:03AM
    Try to use user function and close TfrxReport.PreviewForm in TfrxReport.OnEndDoc event
  • hsmhsm
    edited 2:03AM
    gpi wrote: »
    Try to use user function and close TfrxReport.PreviewForm in TfrxReport.OnEndDoc event

    OK, Thank you.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.