CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2006
    Posts
    5

    How to get formula field value from Subreport to main report

    I want to get Formula field values and grand totals from two subreports and show in page footer of the main report. I am using CR 8.

    Pls help me.

    Thanks in advance.

    Ashish

  2. #2
    Join Date
    Jul 2005
    Posts
    1,083

    Re: How to get formula field value from Subreport to main report

    Shared variables, introduced since Crystal Reports version 7, make it
    easier to pass values from a subreport to the main report.

    Using shared variables requires two formulas:
    one to store the value in a shared variable, the other to retrieve the
    value from the shared variable.

    The most important thing to remember when using shared variables is
    that Crystal Reports must first evaluate the formula where the value is
    stored before evaluating the formula that retrieves the shared variable.

    For example if you want to pass a grand total from the subreport to do
    a calculation in the main report, follow these steps:

    1. In the subreport, create a formula similar to the one below:
    Code:
    //@SubFormula
    //Stores the grand total of the {Orders.Order Amount} field
    //in a currency variable called 'myTotal'
    WhilePrintingRecords;
    Shared CurrencyVar myTotal := Sum ({Orders.Order Amount})
    2. Place this formula in your subreport.
    3. In the main report, create a formula that declares the same variable name:
    Code:
    //@MainFormula
    //Returns the value that was stored in the shared currency variable called
    //myTotal in the subreport
    WhilePrintingRecords;
    Shared CurrencyVar myTotal;
    myTotal
    4. Place @MainFormula in a main report section that is beneath the section
    containing the subreport.

    For the shared variable to return the correct value in the main report,
    you must place @MainFormula in a main report section that is beneath
    the section containing the subreport.
    This ensures Crystal Reports evaluates the @SubFormula before @MainFormula.

    One way to do this is to insert a section below the section containing
    the subreport, and place @MainFormula in this new sub-section:
    · On the 'Format' menu, click 'Section'.
    · On the 'Sections' list, click the section containing the subreport.
    · Click 'Insert' (at top of dialog box). This inserts an additional
    subsection.
    · Click 'OK' to return to the report, and insert @MainFormula into this
    new subsection.

    The next time you preview the report, @MainFormula displays the value
    from the subreport.
    In this particular example, that value was the grand total of the
    {Orders.Order Amount} field.

    5. Once you have verified that @MainFormula is returning the correct
    value from the subreport, you can include this formula in other
    main report formulas, such as:
    Code:
    //@NewFormula
    //includes data from subreport
    {@MainFormula}+ Sum ({Customer.Last Year's Sales})
    Place this formula in the same section as @MainFormula, or in a section
    further down on the report.

    I hope You have now successfully shared data from a subreport with the
    main report.

  3. #3
    Join Date
    Sep 2006
    Posts
    5

    Thumbs up Re: How to get formula field value from Subreport to main report

    Hi jggtz

    Thanks for your valuable response.

  4. #4
    Join Date
    Mar 2008
    Posts
    5

    Smile Re: How to get formula field value from Subreport to main report

    Thanks for posting this request and response. I was just about to ask this question. I'll try when I get to the office later today and post my results.

    THX! THX! THX!

  5. #5
    Join Date
    Mar 2008
    Posts
    5

    Question Re: How to get formula field value from Subreport to main report

    I get this error when creating my formula in the subreport:

    "GROUP SPECIFIED ON A NON-RECURRING FIELD"

    I'm uncertain what that means.

    Any suggestions!

  6. #6
    Join Date
    Dec 2008
    Posts
    1

    Re: How to get formula field value from Subreport to main report

    Using the help posted... i could get the sum of amount from subreport to main report. but i am not able to use this formula to some other formula in main report.. not getting any result in new formula.. how do i?

  7. #7
    Join Date
    Jul 2011
    Posts
    2

    Talking Re: How to get formula field value from Subreport to main report

    hi

    you can refer to this article :
    http://leumorc.blogspot.com/2011/07/...rt-to-sub.html

    hope it solves your problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured