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

printing data or if empty record printing other text

edited May 2004 in Subreports
i have a mainreport with several subreports. each subreport may or may
not actually contain data. if there data it prints; if no data i want
its title to print but i have a label i want to print vs all the data.
main report [group headers]
subreport 1 [title]
[detail - actual data] or 'no reportable data']
subreport 2 [title]
[detail - actual data or 'no reportable data']


i have the detail pipelines skipwhennorecords=false; i have the
subreport noDataBehavior set to ndBlankreport. i've added code behind
the 'onNoData' event. my problem is that the events for printing the
detail band print before the onNoData so i cannot set the label
properties to visible/invisible. i've attempted moving the data into a
section so i could control all the data by simply making the section
visible (vs many individual controls) or not, but again it gets printed
before the onNoData event.

what's the best way to do this?

thanks!
-martha

Comments

  • edited May 2004
    Hi Martha,

    Inside the DetailBand.BeforePrint event you can manually check to see if a
    datapipeline contains no records, then set the visibility of certain
    components on your report accordingly. Something like the following...

    uses
    ppTypes;

    procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
    begin
    if ((ppdaNoRecords in FMasterDataPipeline.State) or
    (FMasterDataPipeline.BOF and FMasterDataPipeline.EOF)) then
    ppRegion1.Visible := False;
    end;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    hi thanks. that's getting me closer. however my problem now is that
    the region isn't printing. since i'm relatively new at this (1 week)
    i'm not sure if i using the best approach. in the subreport onprint i
    check for the ppdaNorecord state and set the region to print (either the
    region with data or the region with a label stating no data). however
    what i get is just the title and then the next subreport. i tried the
    same code in both the subreport onprint and the subreports' detail band
    beforeprint. same result.

    region1 has several data fields:

    1a text $99.00
    1b text $ 0.00

    region 2:
    *** no reportable income ***


    what i need is:
    group 1
    subreport1 title
    detail band: if data - region1
    else region2
    subreport2 title
    deail band

    at the moment i'm getting
    group 1
    subreport1 title
    subreport2 title
    detail band

    any suggestions?

    thanks!
    -martha



  • edited May 2004
    Hi Martha,

    First be sure the SubReport's NoDataBehaviors (available in the Object
    Inspector) has ndBlankReport set to True. The rest of the options should be
    set to False.

    In my testing, I added the following code to the DetailBand.BeforePrint
    event of the first subreport and this seemed to work in the case that when
    there was no data one region appeared and when there was data, the other
    appeared.

    procedure TForm1.ppDetailBand2BeforePrint(Sender: TObject);
    begin
    if (ppdaNoRecords in ppDBPipeline1.State) then
    begin
    ppRegion1.Visible := False;
    ppRegion2.Visible := True;
    end
    else
    begin
    ppRegion1.Visible := True;
    ppRegion2.Visible := False;
    end;

    end;

    I went ahead and posted the test application I created so you can take a
    look at it if you like... Hope this helps.

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

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    thanks very much. i apparantly had missed a shiftrelative and the 2nd
    subreport was overlaying the detail of the first subreport - but not
    it's title.

    i have one further question i hope you can help me with. perhaps it's
    just best to describe what i want - it's not what i getting.

    we have a master table (account, stmt, type) and several detail tables
    based on stmt:
    master (account1, stmt1, B)
    master (account1, stmt2, I)
    master (account1, stmt3, M)
    master (account2, stmt4, B)
    master (account3, stmt5, I)
    master (account3, stmt6, D)

    detail-B (stmt1, $)
    detail-B (stmt4, $)

    detail-I (stmt2, $)
    detail-I (stmt5, $)

    detail-M (stmt3, $)

    detail-D (stmt6, $)

    i'm using groups to break on account (since there's really more
    information but account in the inner most break)

    header: Account 1
    Address ....

    subReportB - title
    detail $region
    subReportI - title
    detail $region
    subReportM - title
    detail $region
    subReportD - title
    detail - region no data
    ----------------------------
    header: account 2
    address ...

    subReportB - title
    detail - region no data
    subReportI - title
    detail - region no data
    subReportM - title
    detail - region no data
    subReportD - title
    detail - region no data
    --------------------------
    header: account 3
    address ...

    subReportB - title
    detail - region no data
    subReportI - title
    detail - $region
    subReportM - title
    detail - region no data
    subReportD - title
    detail - $region


    it appears that it's running each subreport for each record which is ok,
    but what i want to happen is at the end of the account - before the next
    record if any subreports didn't have data to print the subreports with
    the 'no data' region enabled.

    does this make sense and can you suggest how to approach this layout?

    thanks very much!
    -martha












  • edited May 2004
    Hi Martha,

    The approach you describe below should work correctly. Be sure you are
    linking each detail table properly to the Statement field of the master
    table. Then using the same method I described in my earlier posts, you can
    check to see if the detail reports actually have data and enable the nodata
    region as you need it.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    hi nico, thanks for being so patient. my problem is that a master
    record only links to a single detail record. it takes several master
    records for the same account to bring in all the details. it appears
    the way i have my report structured that for each master it run through
    all the possible subreports. so if i have a master with only a single
    detail - everything is fine since there are no other detail records.
    but if the account has 3 master records / 3 detail records for each
    master it goes through the subreport list once for each master instead
    of what i need which is once for each account group. so what i'm getting is
    group / account 1
    (master1 (account 1, stmtB))
    subreportB - have data
    subreportD - no data
    subreportI - no data
    subreportM - no data
    subreportO - no data
    (master2 (account 1, stmtI))
    subreportB - no data
    subreportD - no data
    subreportI - data
    subreportM - no data
    subReportO - no data
    (master3 (account 1, stmtM))
    subreportB - no data
    subreportD - no data
    subreportI - no data
    subreportM - data
    subreportO - no data
    end group account 1

    where what i really want is the all master for a single account (in this
    case 3 master) combined

    group / account 1
    (Master 1 (account 1, stmtB))
    subreportB - have data
    .... no master / detail for stmt D
    subreportD - no data
    (Master 2 (account 1 , stmtI))
    subreportI - have data
    (Master 3 (account 1, stmtM))
    subreportM - have data
    .... no master / detail for stmtO
    subReportO - no data

    does this make any sense? which is way i was wondering if i need a
    different approach. the master are ordered such i know if i have a
    detail M and haven't printed a B or I or D i need to print those
    subreports with no data.

    thanks for any suggestions.
    -martha

  • edited May 2004
    hi, well with several flags to track if a subreport has been printed and
    additional subreports for each in the acct footer to print the no
    data message it's beginning to look like the report we need. one other
    question. one of the details can have multiple statements. is there a
    way to iterate through all the detail in a single subreport? don't want
    to repeat header and want the summary for all detail in the one subreport.


    subreport B - header subreport B
    detail 1
    detail 2
    detail 3
    summary subreport B
    subreport I - header
    detail / no data
    subreport M - header
    detail / no data

    thanks!
    -martha

  • edited May 2004
    Hi Martha,

    Sorry if I'm way off base on this one :). A SubReport will only traverse
    the data that it is connected to. If you would like to see the detail
    records inside the subreport, you will need to either connect the subreport
    to another pipeline or place another embedded subreport inside there that is
    connected to another pipeline. If you are by chance just creating a summary
    subreport to show everything, you will need to create another dataset that
    is not linked in a Master - Detail relationship and connect that to the
    subreport.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    nope, that put me on the right track. i created another pipeline that
    used different set of keys for the one table that could have multiple
    detatils. i also set a flag to know to know that when the master
    traverses the actually record based on stmt to just skip it. works and
    looks great. this was an evaluation for purchase and needed to know if
    it could handle the most complicated of our reports ;-). purchased a
    copy (with more to come) and have received my license to use.

    so again thanks so much!
    -martha


This discussion has been closed.