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

SkipWhenNoData question

edited July 2003 in General
Hope I explain this properly.

I have a Master/Detail report that my users run on their customers. When it
is run on a single customer it works properly. When its run on multiple
customers I have a problem. If I set SkipWhenNoData to true on my report
Customers don't get printed when there is no detail data for them. When I
set SkipWhenNoData to false I get 1 line for each customer that doesn't
belong to that customer (basically the details for the customer that has
details gets mixed in with the customers that have no details). What I
would like is for a line to come up that says "No data available" when there
is no data and the data to come up when there is data available for that
customer. This used to work when I had my Querys tied together through the
DataSource property. When I switched my reports around to improve the speed
I removed that link and linked my Querys together by the datapipeline
through the MasterDataPipeline property. The way I was accomplishing this
before is line this.


In the BeforeGenerate event for my detail band I had the following code:

procedure TfrmAlertGroupReport.ppDetailBand4BeforeGenerate(Sender: TObject);
begin

if (qryGroupAlerts.RecordCount = 0) then // If there were no details then
show the "No data available" label
ppLabel10.Visible := True
else // else
hide the "No data available" label
ppLabel10.Visible := False;

end;

this seemed to work but now the detail Query always has results (since I'm
not doing the master detail the same way).

How can I accomplish this?

How do I determine if a Master has no details so I can hide the RichText
(that shows the normal data) and display the "No data available" label?

Thanks in advance,
Rodger

Comments

  • edited July 2003
    Hi Rodger,

    Check out the Report.OnNoData event to find out when the master has no
    details. You can then use this event to set your rich text to display a
    different message.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003
    Is there a demo of this? The even never seems to fire.

    Thanks in advance,
    Rodger


  • edited August 2003
    Correction:
    Is there a demo of this? The NoData event never seems to fire.

    Thanks in advance,
    Rodger


  • edited August 2003
    Hi Rodger,

    Here is an example of using the OnNoData event. Hope this helps.

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

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003
    Well your example seems like the process is really simple. But I had a
    couple questions since I still can not seem to get mine to work.

    1) Your example is a simple report mine is a Master/Detail does that event
    only get fired when it can not find the Master item? I have mine where it
    can find the master but there are no details and the event never gets fired
    off.

    2) You change the text that gets displayed in the center of the screen.
    Could you also assign the text to the TppDBText component so that the text
    appears where your TppDBText is?

    3) On one of my reports the Main detail band contains 2 sub reports when go
    off and generate 2 different parts of the report. If the master on one of
    those 2 parts does not have any details how do you tell which subreport
    generated the NoData event so that I could change the text of the
    appropriate TppDBText for that sub report?

    Hope that is clear, Thanks in advance,
    Rodger


  • edited August 2003
    Hi Rodger,

    1. The NoData event fires when no data is found by the data pipeline
    connected to a report. If you are using a Master-Detail report, and you
    want an event to fire when there is no data in the Detail dataset, you may
    need to use the NoData event on the subreport that is connected to your
    detail dataset.

    2. Yes, you could assign new text to a component that already exists on a
    report.

    3. Since you will have to use two separate NoData events (one for each
    subreport) you could perhaps include a flag that lets you know which
    subreport contains no data and then change the text accordingly.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003
    Nico,

    1) Problem fixed.

    2) Can't seem to get this to work. in the Subreport NoData event I have the
    following code and I do not get anything displayed.

    procedure TfrmAlertReport.ppChildReport1NoData(Sender, aDialog: TObject;
    var aShowDialog: Boolean; aDrawCommand: TObject;
    var aAddDrawCommand: Boolean);
    begin

    ppDBRichText2.RichText := 'No data available for this customer.';

    end;

    3) I think if I can get #2 working I can get this to work.

    Thanks again,
    Rodger



  • edited August 2003
    Hi Rodger,

    I'm sorry, I missunderstood the last question. As you could see in the
    example I sent you, a new draw command was created in the NoData event to
    display the given text. The reason for this was that when there is no data,
    ReportBuilder will not generate any draw commands. The reason you are not
    seeing the text you entered is that the draw command for the TppRichText is
    not being generated. You will need to create a new TppDrawRichText draw
    command and place the text in there to see the results you are after.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003
    I am either not following you or I'm completely lost. How do I do this?
    Create the new TppDrawRichText command I mean

    Thanks for all you help on this,
    Rodger


  • edited August 2003
    Hi Rodger,

    Each item in a report is made up of a draw command of some type. In the
    NoData event, you will need to create a new TppDrawRichText command to
    replace the one not being generated. For instance you will need to do
    something like the following:

    lMyDrawCommand := TppDrawRichText.Create(Report);
    lMyDrawCommand.Left := liLeft;
    lMyDrawCommand.Top := liTop;
    lMyDrawCommand.Width := ... etc.... etc....

    Then you will need to fill the RichTextStream with some RTF to display the
    No Data message you want.

    I am a bit unclear why this message needs to be in .rtf format. It would be
    much easier to format a text component to display something similar using
    the method in the example I sent.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003
    Actually this message can be anything. The normal text is formatted, which
    I'm working with Jim to figure out why that is not working. We had just
    talked in the very beginning about assigning my custom text to the RichText
    instead of the way I was doing it which was I had another Text component
    that I just turned the visibility on and off, in order to display this text
    when there was no data. I'm open to any way.

    Thanks for your help,
    Rodger


  • edited August 2003
    Hi Rodger,

    I'm not sure if you got this working but here is an example that does what I
    think you want. Hope this helps.

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


    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.