Print Empty rows if dataset is empty

Hi

I have the situation where I need to print a band even if there are no rows for the dataset, and it must always print the band at a specific height (well the height of 3 records).
Report Layout: (actually subreport, but shouldn't make a difference I think)

Header Band (must ALWAYS be printed)
MasterData band (must ALWAYS be printed - dataset returns only 3 or less rows if there IS data, if there is no data or less than 3 rows then the band must print to the height of 3 rows)
Footer band (must ALWAYS be printed)


Any suggestions?

TIA
Regan

Comments

  • edited 1:22AM
    Make bands as you described and be sure to check the property Print if Detail Empty in your master data band

    You may want to look at other psots on child fillers if you desire to reserve or fill up the empty space in your report
    Be sure you have print on first and last page checked for your header and footer
    Hope that helps
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 1:22AM
    In the script, in the OnBeforePrintEvent of any of the bands (probably the header, maybe even of the page, if it's a simple report), check for the number of records of your dataset, and if = 0, set the masterdata1.rowcount property to 3 (the number you said you want its height to be).
    something like:
    Page1.OnBeforePrintEvent();
    begin
    if MyDataset.recordcount = 0 then
      masterdata1.rowcount := 3
    else
      masterdata1.rowcount := 0;
    end;
    

    The rowcount set to anything other than 0 means you are forcing it to be printed X number of times, regardless of the dataset (even if it doesn't have one).
    The Header and Footer should behave as you expect with this.
    I hope it helps
  • gordkgordk St.Catherines On. Canada.
    edited 1:22AM
    the rowcound property has no effect when the band is connected to a dataset., it only controls howmany times the band outputs its objects to the output page. if the band is connected to a dataset the dataset controls the output.
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 1:22AM
    gordk wrote: »
    the rowcound property has no effect when the band is connected to a dataset., it only controls howmany times the band outputs its objects to the output page. if the band is connected to a dataset the dataset controls the output.

    Well, in that case...
    Page1.OnBeforePrintEvent();
    begin
    if MyDataset.recordcount = 0 then
       begin
         masterdata1.Dataset := nil; 
         masterdata1.rowcount := 3;
       end
    else begin
         masterdata1.Dataset := MyDataset;
         masterdata1.rowcount := 0;
         end;
    end;
    

    (It's getting a little dodgy at this point, if this doesn't work, try another way)
  • gordkgordk St.Catherines On. Canada.
    edited 1:22AM
    that would result in the first record of the master data printing n times unless you write code to control the dataset movement.
    if your bands and record spacing is always the same height(not stretching )
    instead of using framesof memos add an overlay band and use lines.
    tip on overlays they are realy underlays, set the designer page to large height in design mode
    add your overlay band below all others after designing
  • edited 1:22AM
    Hi All

    Thanks for the suggestions. I found this forum topic which gave me my final solution [topic="5791"]Repeating the MasterData for n-times[/topic].
    Below is my final code. I would be keen to know, if there is a better way of doing this.

    var
    bPrintedLastTop3International : Boolean;
    bPrintedLastTop3National : Boolean;
    dsTop3National: TfrxDataSet;
    dsTop3International: TfrxDataSet;

    ...

    procedure MasterData21OnBeforePrint(Sender: TfrxComponent);
    begin
    if (Engine.FinalPass) then
    if (dsTop3National.RecordCount>0)
    and (dsTop3National.recno <= dsTop3National.recordcount)
    and (not bPrintedLastTop3National) then
    begin
    if (dsTop3National.recno = dsTop3National.recordcount) then
    bPrintedLastTop3National := True;
    Memo24.Text := dsTop3National.Value;
    dsTop3National.Next;
    end
    else
    Memo24.Text := '';
    end;

    procedure MasterData22OnBeforePrint(Sender: TfrxComponent);
    begin
    if (Engine.FinalPass) then
    if (dsTop3International.RecordCount>0)
    and (dsTop3International.recno <= dsTop3International.recordcount)
    and (not bPrintedLastTop3International) then
    begin
    if (dsTop3National.recno = dsTop3National.recordcount) then
    bPrintedLastTop3International := True;
    Memo27.Text := dsTop3International.Value;
    dsTop3International.Next;
    end
    else
    Memo27.Text := '';
    end;

    //Main script begin ... end
    begin
    dsTop3National := Report.GetDataset('fdtsHL_Top3National');
    dsTop3International := Report.GetDataset('fdtsHL_Top3International');
    if (Engine.FinalPass) then
    begin
    dsTop3National.First;
    dsTop3International.First;
    bPrintedLastTop3International := False;
    bPrintedLastTop3National := False;
    end;
    end.

    Regards,
    Regan
  • edited 1:22AM
    Hi

    Sorry, forget to add the RowCount property of the MasterBands were set to 3.

    Regan

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.