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

Don't print Subreport if the Detail Pipelien has no corresponding record in master pipeline

edited January 2005 in Subreports
I have set Master/Detail DataPipeLine using MasterFieldLinks. I have a
subreport with datapipeline set to detail pipeline (but it contain some
control which display value from pipelineMaster), Now if the Detail pipeline
has no corresponding record with Master pipeline, then I want the subreport
(section type) don't show. How to do this?
I don't want to use SkipwhenNoRecord because I need to display the header
info. plus any other thing.
I have found that when the detail pipeline has no record corresponding to
the headerPipeline, then their value is different, coud I use this property
to alter the visible property of subreport in Beforeprint?

Comments

  • edited January 2005

    If you want to hide the subreport then in band that contains the subreport,
    place the following in the BeforePrint event:

    if plDetail.Bof and plDetail.Eof then
    subreport.Visible := False
    else
    subreport.Visible := True;

    For details on NoDataBehaviors, see the online help topic in RBuilder.hlp.



    --
    Nard Moseley
    Digital Metaphors Corporation
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited January 2005
    I have try this method but it don't work! I think this is because the detail
    pipeline has record but just not corresponding to the current master
    pipeline record. Instead I find that the following seems to work
    if Masterpipeline['KeyFieldName'] <> DetailPipeline['ForeignKeyFieldName']
    then
    subreport.visible = false
    else
    subreport.visible = true;
    Is it true?

  • edited January 2005

    That looks like an equally valid approach. :)

    If the master/detail linking relationship is defined properly then the code
    I suggested should also work.

    Here is an article on defining linking relationships...


    ------------------------------------------------------
    Tech Tip: Linking SQL Queries for Master/Detail Data
    ------------------------------------------------------

    The following example shows two options for linking SQL queries to create a
    master/detail relationship.

    In this example, we are using Delphi's DBDemos data to create a
    Customer/Order relationship. Thus we wish to link the Orders detail to the
    Customer master.

    I. Delphi Query Linking
    ------------------------

    a. Set the detail TQuery.DataSource property to point to the master
    query's TDataSource component.

    b. In the SQL "Where" clause for the detail query use a ':' followed by
    the linking field name from the master:

    example
    select *
    from orders
    where orders.CustNo = :CustNo

    Now each time the master record position changes, the detail query will
    automatically be refreshed with the correct result set.


    II. RB DataPipeline Linking
    -----------------------------

    a. Set the detail DataPipeline.MasterDataPipeline to point to the master
    DataPipeline.

    b. Use the detail DataPipeline.MasterFieldLinks property to define the
    linking relationship

    c. In the SQL for the detail, retrieve all records and sort them by the
    linking master field:

    select *
    from Orders
    order by CustNo


    Notes:

    1. Using RB DataPipeline, each query is executed only a single time - thus
    performance is much faster.

    2. RB Professional and Enterprise Editions include a visual Data environment
    for creating SQL queries, defining linking relationships, and creating
    Ask-At-Runtime parameters. Using the RB tools you could create the above
    linked queries in about 10 seconds.


    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com





    --
    Nard Moseley
    Digital Metaphors Corporation
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.