cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Parameters to anf from Sub-Reports

Former Member
0 Kudos

I have a report with two subreports in it, and I want to be able to tell the main report about the data in the sub-report so I can supress a detail section if the sub-report contains certain data. How do I pass a parameter from the sub-report to the main report?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi dhillard,

I have a slightly different aproach to your problem:

In the main report type the following code:

shared booleanvar n;

if Count() > 10

then n:= true

else n:= false;

n;

In the subreport type a similar code of the type:

shared booleanvar n;

if n = true then

crGray

else

crSilver

This should work fine.

Thanks,

Amogh

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

You want to link your sub-report with parameters in the main report. If you want to suppress the data if certain results appear in the sub-report, you want to use the Section Expert in the main and sub-report. In the sub-report, you would supress the details going by your criteria; in the main, you probably want to activate 'suppress blank section' so you don't have a gap in the report.

Is that what you were looking for? If not, please provide more details.

Regards,

Heather

Edited by: Heather Wilkinson on Apr 2, 2009 3:41 PM

Former Member
0 Kudos

I could be wrong, but I do not believe you can pass values from the subreport to the main report using the subreport parameters. What you need to do is create a formula field in the subreport. That field sets a Shared variable to the value that you want to pass back to the main report, then in the main report, create another formula field, referencing the same shared variable. For example, in the subreport put (basic syntax):


shared totalRows as number
totalRows = count({database.field})
formula = ""

and in the main report, you can use something like


shared totalRows as number
if totalRows > 10 then
  formula = crRed  ' background color, for example
else
  formula = crNoColor
end if

HTH,

Carl

Former Member
0 Kudos

Passing a variable from subreport to main report and vice versa

Declare a variable as shared in the subreport.

Shared numberVar NoOfrecords;

Assign some value to this variable,

Shared numberVar NoOfrecords :=Count()

Then in the main report, create a formula and in that formula again declare the vairable and use it as u like

//Declaration

Shared numberVar NoOfrecords;

//If you want to supress a section based on this count,then

if NoOfrecords = 0 then TRUE

click ok..

NOTE:

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.

Very Important : Dont just create the formula, u have to place this forula somewhere as mentioned above. If u dont want to show this formula value,then hide it by changing its colour to white or by some other way. If u dont place the formula in the report,it wont work.

and same thing applies when passing values from main report to subreport.

In this case define the @MainFormula first and then @SubFormula.

I have used this successfully in my report.

Former Member
0 Kudos

Thanks for the help.

I was able to pass data from the Sub-Report to the Main-Report, but just like Amit noted the main-report formula did not get evaluated until the next detail section. So I still am not able to accomplish what I was hoping to.

What I am trying to do is:

If any field in the sub-report = u201CPerfusion Arterial/Venousu201D, then Suppress the detail section that contains the sub-report.

I can suppress the section after the section containing the sup-report with u201CPerfusion Arterial/Venousu201D as the value of one of the rows. But this doesn't help.

Any other suggestions?

DHilliard

Former Member
0 Kudos

Hi You can place the sub report values in the below section of the sub report and in section expert > Check underlay section so that it prints in the same section as the sub report in the preview mode.

Regards,

Vinay

Former Member
0 Kudos

But I don't want to display the values from the sub-report. I want the whole detail section suppressed.

Former Member
0 Kudos

How can I attach / upload a PDF to show what the report looks like?

Former Member
0 Kudos

Hi Instead you can try add a command within the sub report like Select count(Field) as cnt from table where field = 'Condition'

Do not link this command with other tables in the sub report detail section you can conditionally suppress if the cnt field > 0.

Hope this helps!

Regards,

Vinay

Former Member
0 Kudos

Or, add a parameter to the subreport that will suppress everything that the subreport prints. Call it to find out if the data contains the value you are looking for in one detail section (without printing), then call it again (with printing) in a second detail section, which would be conditioned on the first call's results.

HTH,

Carl