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

How do I hide the detail if the detail count is not a specified value

edited July 2002 in General
I am trying to print a report that has a header, group header, and detail
but only want to print the group header and detail where the detail count is
a specified number. I have tried all sorts of things, but can't get it to
work.

Any help appreciated,

Regards
Jeremy Knowles

Comments

  • edited July 2002
    You'll need to check the detail count before the header begins to print.
    Hide the header, group header, detail and group footer until a detail set
    comes along that has the appropriate number of records. In the BeforePrint
    of the Header:

    if (Table2.RecordCount = 10) then
    begin
    ppReport1.Header.Visible := True;
    ppReport1.Detail.Visible := True;
    ppReport1.GroupHeader[0].Visible := True;
    ppReport1.GroupFooter[0].Visible := True;
    end
    else
    begin
    ppReport1.Header.Visible := False;
    ppReport1.Detail.Visible := False;
    ppReport1.GroupHeader[0].Visible := False;
    ppReport1.GroupFooter[0].Visible := False;
    end;

    Assuming Table2 is the detail table and is linked to the master.

    If only one table or query is being used, then you'll need to count the
    records in the group manually instead of using RecordCount. Just bookmark
    the dataset, traverse to the next group break, then restore the dataset.

    function TForm1.CountRecordsInGroup: Integer;
    var
    lCurrentRecord: TBookmark;
    lsCurrentValue: String;
    lsBreakValue: String;
    begin

    lCurrentRecord := Table1.GetBookmark;

    liCount := 0;
    lsBreakValue := Table1.['YourGroupFieldNameHere'].AsString;
    lsCurrentValue := lsBreakValue;

    while (lsCurrentValue = lsBreakValue) and not(Table1.EOF) do
    begin
    Table1.Next;

    lsCurrentValue := Table1.['YourGroupFieldNameHere'].AsString;

    Inc(liCount);
    end;

    Table1.GotoBookmark(lCurrentRecord );

    Result := liCount;

    end;

    --
    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited August 2002
    I am also trying to do something very similiar, i.e. show only the details
    for upto detail count to a certain number(N). I tried the following:
    Place a DBCalc component in the detail band and set calculations
    to count. This will number the detail bands. Next in the report beforeprint
    procedure, test the value of the DBCalc component. If value is less than N,
    make the detail bands visible, else make visible equal to false.
    I was only partially successful this method, as not all the detail band
    components would show when they were supposed to.

    I would like to know if there is a better way to do this. Thanks in advance.
    Prathy Kukkalli



  • edited August 2002
    Some databases support this in their SQL specifications. For example:

    SET ROWCOUNT 10
    SELECT * ...

    or

    SELECT TOP 10 * ...

    or I've even seen something like

    SELECT FROM table LIMIT 0,10.

    Take a look at the specific set of SQL supported by your DB. If by chance
    your BD does not support anything like this then you can also accomplish
    this by using a temporary table. Select the original data into a temp table
    adding a calculated column which is the count of the record. This way you
    can also order the data on the first select. Then make a second select
    against the second table retrieving all values whose value in that column is
    less then your desired record count.

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

This discussion has been closed.