If rowcount or recordcount = 0 - show message

I would like to show a message in a label if no rows are found.
The results come from a BDE query and are displayed on a MasterData band.
I've tried using the RowCount property of the MasterData band and the RecordCount of the query.
I've tried it both ways in a click event of an OK button and in the onBeforePrint event of the MasterData band and the label.
I'm using pascal.
Memo8 is the name of my label. It is currently in the Report Title header.
TfrxMasterData is the MasterData band
Encounter holds the result of the query.

I need something like this.
If length(TfrxMasterData.RowCount) = 0 Then begin
      Memo8.Visible := True;                                                                      
      Memo8.lines.Text := 'no data';
end Else begin
      Memo8.Visible := False;                                                                      
      Memo8.lines.Text := '';
end

or something like this
If TfrxMasterData.RowCount = 0 Then begin
      Memo8.Visible := True;                                                                      
      Memo8.lines.Text := 'no data';
end Else begin
      Memo8.Visible := False;                                                                      
      Memo8.lines.Text := '';
end

or something like this
If Encounter.RecordCount = 0 Then begin
Memo8.Visible := True;                                                                      
      Memo8.lines.Text := 'no data';
end Else begin
      Memo8.Visible := False;                                                                      
      Memo8.lines.Text := '';
end

Any suggestions on what and where? Let me know if I need to provide more info.
Thanks.

Comments

  • edited 8:11PM
    DavidWIII wrote: »
    I would like to show a message in a label if no rows are found.
    The results come from a BDE query and are displayed on a MasterData band.
    I've tried using the RowCount property of the MasterData band and the RecordCount of the query.
    I've tried it both ways in a click event of an OK button and in the onBeforePrint event of the MasterData band and the label.
    I'm using pascal.
    Memo8 is the name of my label. It is currently in the Report Title header.
    TfrxMasterData is the MasterData band
    Encounter holds the result of the query.

    I need something like this.
    If length(TfrxMasterData.RowCount) = 0 Then begin
          Memo8.Visible := True;                                                                      
          Memo8.lines.Text := 'no data';
    end Else begin
          Memo8.Visible := False;                                                                      
          Memo8.lines.Text := '';
    end
    

    or something like this
    If TfrxMasterData.RowCount = 0 Then begin
          Memo8.Visible := True;                                                                      
          Memo8.lines.Text := 'no data';
    end Else begin
          Memo8.Visible := False;                                                                      
          Memo8.lines.Text := '';
    end
    

    or something like this
    If Encounter.RecordCount = 0 Then begin
    Memo8.Visible := True;                                                                      
          Memo8.lines.Text := 'no data';
    end Else begin
          Memo8.Visible := False;                                                                      
          Memo8.lines.Text := '';
    end
    

    Any suggestions on what and where? Let me know if I need to provide more info.
    Thanks.

    Good Morning,
    try to use the BDE-Query to get the RecordCount.
    Add it to the lower begin/end.-part. This part will execute before the report were filled.

    Greets ReeBo
  • gordkgordk St.Catherines On. Canada.
    edited 8:11PM
    David
    if you have detail data this could be done in the mdband using detailbandsdataset.recordcount property
    and an [iif((detaildata1.dataset.recordcount = 0),true value,false value)] in the memo
    rowcount property only applies to virtual datasets.
  • edited November 2013
    gordk wrote: »
    David
    if you have detail data this could be done in the mdband using detailbandsdataset.recordcount property
    and an [iif((detaildata1.dataset.recordcount = 0),true value,false value)] in the memo
    rowcount property only applies to virtual datasets.
    I don't have a detail band on the report. I just have the master data band and some group headers. I'm not sure if I can use that code in a header to reference
    the dataset in the master data band. I'm still learning. It's possible that I could be using a detail band instead of the master.
    It would be helpful if I could reference the master band from the header.

    Thanks for your help.

    Thanks to Reebo too. I'll try your suggestion later after doing other things. I'm not yet sure if I'll need to store the record count in a variable and then reference the variable in my code. or if I'll reference the record count as a "property" of the BDE query.
  • gordkgordk St.Catherines On. Canada.
    edited 8:11PM
    Hi David
    here is a tip when using group headers if you want to print
    something in the group header that comes from values after the groupheader
    you must make the report 2pass and gather the values in an array then subthe
    array value in the second pass.
  • edited 8:11PM
    I'm looking through the manual and attempting to use 2 pass and an array.

    I've also tried getting the record count from the query. I still haven't worked out how to get Fast Reports to read the record count. I've tried storing the rowcount in a variable but haven't been able to get that variable to my code. I'll post my attempts later to
    see if I can get it working that way.

    I want to get it working both ways because I think it will help in the future.

    I'm also trying another way. I placed one of the values from the query in the ReportTitle. Then a statement in a label on that band checks to see if it has a value.

    The memo with the value reads
    [myQuery."myQueryValue"]
    

    That is a value that stays constant on the report. That works.

    In the label I've tried
    [iif((length(trim(memo.lines.text)) = 0),'nothing','something')]
    

    and
    [iif(((memo22.lines.text) = ' '),'nothing','something')]
    

    In both cases, the label always reads 'something' even when the query does not return rows.

    Is there a way to get the above to work?

    Thanks for all the help.
  • edited 8:11PM
    Hi.

    If your data comes from a query, you should be able to do this in the main code area of the report:
    MyQuery.Open;
    MyQuery.First;
    If MyQuery.EOF then
      Memo8.Visible := True                                                                      
    else
      Memo8.Visible := False;
    

  • edited 8:11PM
    At my test-Report this works:
    begin
      ADOQuery1.Open;                                
      Memo1.Visible := ADOQuery1.RecordCount = 0;                                                
    end.
    
  • edited November 2013
    I got it to work by setting the page to double pass and using the following in the memo OnBeforePrint event.
    wrote:
    procedure Memo8OnBeforePrint(Sender: TfrxComponent);
    begin
    if Engine.FinalPass then
    If myQuery.RecordCount = 0 Then begin
    Memo8.Visible := True;
    Memo8.lines.Text := 'There are no encounters for Client # ' + ClientNo + ' for the dates ' + DateToStr(sdate) + ' to ' + DateToStr(edate);
    end
    end;

    The ClientNo and the two dates are inputs on the form.

    I'm not sure what do with the other suggestions...
    begin
      ADOQuery1.Open;                                
      Memo1.Visible := ADOQuery1.RecordCount = 0;                                                
    end.
    
    MyQuery.Open;
    MyQuery.First;
    If MyQuery.EOF then
      Memo8.Visible := True                                                                      
    else
      Memo8.Visible := False;
    

    I'm sure they are good suggestions and would work if I put them in the right place and did a few other things. I'm just not sure how they apply to what I'm attempting. I will come back to them and try again to see if I can use them in the future.

    Learning about 2pass on gordk's suggestion is what really helped.

    Thanks to all.
  • edited 8:11PM
    I was able to use the following in the Report Start event to control my 'no records' message, and it works great.
    begin
      ADOQuery1.Open;                                
      Memo1.Visible := ADOQuery1.RecordCount = 0;                                                
    end.
    

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.