Solved

crystal reports pass value from subreport to main report

Posted on 2015-02-02
16
963 Views
Last Modified: 2015-02-03
I am trying to return a value from my subreport to my main report, and it's not working.

I have this formula field in the subreport header, which is suppressed:
Shared numbervar Trade := 0;

I have this formula field in the subreport details:
WhilePrintingRecords;
Shared numbervar Trade := {VHMLSVIN.AmtPrice}

The subreport is in the details section of the main report.

I have this formula field in the main report page footer:
Shared numbervar Trade;
Trade := Trade;

I have the value printing in the subreport, and the value is correct.
It's not returning the value on the first record, only on the subsequent records.

What do I have wrong?
0
Comment
Question by:tozz5
  • 6
  • 5
  • 2
  • +2
16 Comments
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Is the subreport for the first detail section on the first page?

How about showing the value in a second detail section?  That will always be built after the subreport is done.

mlmcc
0
 

Author Comment

by:tozz5
Comment Utility
yes, the first detail is on the first page.

tried a second detail section, and that doesn't work either.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Do you have multiple detail sections on a page?

Do you print the page footer on page 1?

mlmcc
0
 

Author Comment

by:tozz5
Comment Utility
only one detail section per page
yes, the page footer is on page 1

I have also tried putting the subreport in the group header, and retrieving the returned value in the details section, and the same results, the first value is not returned
0
 
LVL 1

Accepted Solution

by:
michaeljwalter earned 334 total points
Comment Utility
Well, you need to be sure that the subreport is processed before the detail of the first record is displayed. If moving the subreport to a details a and the record info to a details b section won't do it, you might like to create a group for each record (say, on record number key or the like), so that you get a group for every record. Then put the subreport in the group header, and the detail data for the record in the group footer.

If that doesn't do it, I'd suspect it's your WhilePrintingRecords in the subreport. Either add WhilePrintingRecords to the main report as well, or better yet, remove it from the subreport unless it's absolutely necessary for some reason which isn't obvious from your question.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
I notice you don't have a formula to declare the shared variable in the report header. Try adding this formula to the report header

WhilePrintingRecords;
Shared numbervar Trade;

Open in new window



WhilePrintingRecords is not required in the formula.  Shared variables are automatically evaluated in that pass.  I add it as an immediate reminder of when the formula will be evaluated.

You can change the formula in the page footer to

WhilePrintingRecords;
Shared numbervar Trade;
Trade

Open in new window


mlmcc
0
 

Author Comment

by:tozz5
Comment Utility
I created a group, put the subreport in the group header, put the detail in the group footer, removed the "whileprintingrecords" from both formulas, and still am getting the same result...  
first doesn't return the value (even though it is printing correctly in the subreport), but subsequent records are returning the correct value.

any other ideas?
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Did you add the formula to the report header?

mllmcc
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Assisted Solution

by:michaeljwalter
michaeljwalter earned 334 total points
Comment Utility
I looked a little closer at your question.

You say your subreport formula is:

WhilePrintingRecords;
 Shared numbervar Trade := {VHMLSVIN.AmtPrice}

Since you completely replace the contents of the variable with a single value from the current subreport each time the formula runs, I would expect that when you recall the variable in a page footer, you only see the value of the last subreport on the page. Is that in fact what's happening, rather than not populating in the first record?

I would guess what you want to be doing instead is this:

WhilePrintingRecords;
 Shared numbervar Trade := Trade + {VHMLSVIN.AmtPrice}

When troubleshooting something like this during development, create extra headers and footers temporarily, and place a field which shows you the immediate state of the variable (i.e., recall it) at each step. This will help you narrow down what the problem is.

If I'm correct, I would expect to see, in a group footer following each subreport, that Trade = [value from immediately preceding subreport].
0
 

Author Comment

by:tozz5
Comment Utility
MAIN REPORT, report header field:
Shared numbervar Trade;

MAIN REPORT, group header:
subreport

SUBREPORT, report header field:
Shared numbervar Trade := 0;

SUBREPORT, details field:
Shared numbervar Trade :=  {VHMLSVIN.AmtPrice}
(this displays the correct value)

MAIN REPORT, details field (one per page):
Shared numbervar Trade;
Trade
(this displays 0 for the first page, and the correct values for all subsequence pages)

I don't want the total, I want the different value for each detail line to be returned to the main
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Try this

Change the formula in the main report header to

Shared numbervar Trade;
Trade := -1;

Open in new window


Change the formula in the subreport header to
Shared numbervar Trade;
Trade := -5

Open in new window


mlmcc
0
 

Assisted Solution

by:MacProTX
MacProTX earned 166 total points
Comment Utility
I do think mlcc's suggestion might provide some additional information about where the problem is, and is worth trying, particularly if you create a display formula recalling the variable at each stage of the report.

Initially, you said you were displaying the variable in the main report (post-subreport) in the page footer; above you state that it's in the details section. Making sure it's in a details b section ( when the subreport's in a details a) *should* work, though in my experience, it's not 100% reliable. A group footer, or the page footer, should be more so.

It's been a little while for me, but I worry a bit that the syntax:

Shared numbervar Trade;
Trade

is actually reinitializing the variable (implicitly to 0, even without the explicit assignment of :=0, which mlmcc's suggestion would prove or disprove), then recalling it in its reinitialized state. Try just:

Shared numbervar Trade

for the recapitulation formula.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Can you post the report?

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
I just did a quick test here and the basic idea seems to work.  CR can be a bit weird with how it handles page footers, but I got the expected values.

 Do you actually just have one record per page?  That's pretty unusual, so I just wanted to make sure.  What you should get in the page footer is the value from the subreport in the last detail section on the page.

 Are you hiding/suppressing any records?  If so, then, depending on what you're doing, the subreport could be run for another record that you can't see, and you're getting the result from that record.

 James
0
 

Author Comment

by:tozz5
Comment Utility
kept moving things, and finally got it to work...
subreport is in the group header, and "details" are in the group footer, and it's returning the correct value.
not sure what actually "worked", but it's working.

thanks to all for the help!!
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
Obviously a group header or footer is not the same as the detail section.

 Was the subreport in the group footer before?  If so, maybe it had something to do with how the group footer and page footer are rendered.

 James
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now