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

Showing records only if populated

edited December 2001 in General
This is a repost from a couple of days ago, so i guess it got lost
somewhere.
If not then i apologise.
The question has to do with only printing certain fields if they contain
data.
I have been trying to create a Master/Detail report that
displays the current master record along with the details for this record.
I want most of the details to be displayed in a subreport (which works
fine), but i also want one field from the detail dataset to be displayed
after all the detail records have been printed. I have put this extra field
in a second sub report in the summary section of the first subreport (if you
see what i mean).
Now all this works OK, except that i only want this field to be displayed if
there is actually data in the field.
The field is called 'Terms'.
Now i have written procedures for trying to make the second detail band
invisible if there is no data but i can't get it to work.
I can't event get the compiler to stop on these procedures so i can test it.

I have put together a zipped demo app which i can send you, that uses the
DBDemos tables and if you could need take a look at what i am talking
about.

Thankyou for any help

John

Comments

  • edited December 2001
    I've downloaded your attachment from the news server from a couple days ago.
    I'll try changing the timing of your events a little, to see if I can get
    this approach to work in your example.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited December 2001
    The problem with your demo project is that the subreport1 needs to be set to
    invisible before the detail records have been traversed by the report.

    The best approach is to create a lookup query. The lookup query should
    create a caclulated field for each master record, in order to determine when
    the detail records have at least one non-emtpy Notes field. The lookup
    should only return one record for each master record.

    Another approach, you may be able to get away with moving the detail record
    pointer. Create a method that traverses through the detail records to check
    the value of the notes fields in the detailband's BeforePrint so that you
    can set the visibility of the subreport1, if they are all empty. You'll have
    to check the key linking field value to make sure that you stop on the last
    record of the detail data for the master record. Then move the current
    record poiner back to the record you started with.

    Yet, another similar approach, would be to create the report in two passes.
    Report.PassSetting := psTwoPass. In the first pass, create a list of master
    records that have all empty Notes fields. In the second pass, use this list
    to set the visibility of the subreport1 in its DetailBand.BeforePrint event.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited December 2001
    Thanks for all your help on this Jim.
    I've done it at last. Your Lookup query gave me the idea, that all i needed
    to do (as i am using Clientdatasets, and cannot use queries when offline),
    was to populate another Dbisam InMemory dataset with the Item Notes and
    display them (if any) in another subreport.

    Whole hearted thanks again and have a good break
    John
This discussion has been closed.