Crystal Reports - Subreport with stored procedure as datasource creates a new param and doesn't pass it to the stored proc - crystal-reports

Using Crystal Reports XI, I have a main report. In this report, I have a Formula Field named XXXCompanyFilter. This is set programmatically at run time and I want to pass it to a subreport.
I add a subreport that has a stored procedure as an input parameter. The parameter is named #co.
A Parameter Field is automatically created in my subreport called #co.
I return to my main report and right-click the subreport and choose Change Subreport Links. I choose the Formula Field XXXCompanyFilter from the Available Fields list and move it to the Field(s) to link to: list.
At this point I expect to be able to choose the subreport's #co parameter in the Subreport parameter field to use: drop down, but it is not there. I have unchecked the Select data in subreport based on field: checkbox.
I've tried selecting the ?Pm-#XXXCompanyFilter option, and that (I think) causes a new subreport parameter to be created:
After that, I do get the new subreport parameter to show in the drop down:
However, this new parameter doesn't seem to do anything, and I'm still prompted to enter the #co subreport parameter whenever I run the report. If I enter a value for the #co parameter the report returns the data I expect.
I've created several subreports to see if the behavior changes. I've tried it with the subreport wizard and with subreports I've created normally. I always get a 2nd, non-useful subreport parameter and the #co parameter is never set, so I am prompted for it.
I feel like if I could select the #co parameter in the drop down list it would work as needed.
I've checked out multiple SO posts, and I've googled the issue but everything I find says I'm doing it right. What am I doing wrong, or what do I need to do to make the #co parameter available in the drop down?

I solved this by specifying a database field in the Available Fields list when creating the subreport link and following the instructions in my original post.
Apparently it just won't work if you specify a Formula Field in the Available Fields list. I can't find any documentation on this but that's the conclusion I come to after reaching a solution by trial and error.

Related

Crystal Reports: Setting subreport parameters with one main report parameter [duplicate]

How can we pass a parameter from the main report to a subreport in Crystal Reports XI? I have a parameter in the main report. Now, I want to pass the same parameter to subreports. Please help me.
Right-click on the subreport object and choose Change SubReport Links, then select how the parameter is to be used by the subreport.
Using CodebyMoonlight's solution requires a relation between main report and subreport.
If there is no relation between both of them, you can use Shared Variables to pass values between both of them, as shared variable can be set and displayed anywhere in main report or sub report.
Shared NumberVar x := 5;
Perform following easy steps:
Create New Parameter lets say "StartDate" in Parameter Fields in Field Explorer in Crystal Report
Create New Parameter lets say "StartDateSubReport" in Parameter Fields in Field Explorer in your Subreport
Now in Main report file, Right Click Subreport lets say "EmployeesList.rpt" and click Change Subreport Links menu
Select "StartDate" from Available Fields from Available Fields Tab and click on ">" button to make it vailable to link in subreport
Now bind your "StartDate" which you have made available by selecting it with "StartDateSubReport" in dropdown available in "Subreport Parameter Field to use"
parameter sharing between main report and sub report "Right-click on the subreport object and choose Change SubReport Links, then select how the parameter is to be used by the subreport." works for me
I had the same problem. The main report loaded first and then the subreport. You have to load the subreport before you can use the variable.
I think that using
Right Click and Sub-report Links
or
Shared Var Between Report and Sub-report
Both using Selection formula so it is suitable for limited data only
Selection formula working after loading all records from Database table ... report loading bad performance
so i'm tring to limit rows by passing some parameter from C#/VB and send others from main to sub report
For example if you need the transaction of items in period and you can pass the period parameter from application (c# ..) and using Sub-report Links to send itemID
https://kb.blackbaud.com/articles/Article/52328
Create a parameter field in the main report.
From the main report, right click on the subreport, and select Change Subreport Links.
In the subreport linking window, select the parameter field from the window labeled "Available Fields", and click on the ">" button to move it to the window on the right labeled "Fields to link to"
Below, make sure you have a check next to Select data in subreport based on field.
Below the checkbox, if it is not already there, select the field from the subreport, to which you would like the parameter field linked.
Click OK

Ssrs run only one of the subreports based on parameter

I have a report, and the report has 5 subreports. There is a parameter named "SubreportNumber". I want to run one of the subreports, based on that parameter. Just one of them should run. Effectivity is important in my case. Is this possible?
I'm using an IIF statement to hide (using visibility) my reports based on a parameter value, as described above.
Then I take the same approach when specifying the sub-report parameters.
This can basically be done on any one of the parameters, if the report should be showing then pass the parameter, else pass nothing. (If you pass NOTHING as a parameter to the report, it won't run the report, ie. performance increase...)
Example for Year parameter below:
=IIF(Parameters!SubreportNumber.Value = "1","YEAR(NOW)", Nothing)
You can hide the reports you dont want based on your parameter.
To do this: Go the Report's property, under visibility section. Set Show or hide report based on expression. You can write an expression to hide report depending upon your parameter.
This will just hide the reports. Make sure there are no stored procedure or they will be execute irrespective or whether the report is visible or not.

Including a subreport into a GROUPING section

Crystal Reports: including a subreport into a grouping section?
asked the same question, but I am hoping a comment on the accepted answer is wrong: that it can't be done because the subreport must be in the details section. Also, what the selected answer says to do isn't working (perhaps because of the other detail, no pun intended).
So this looks like a duplicate question, yet the original question does not appear to be answered, and certainly the accepted "answer" is not usable by me.
(see also How to handle a duplicate question when the original has an accepted answer that is not really acceptable?)
My subreport can list one to many items, each of which can join to one or more items in the main report details. The common field they join on is the grouping item. So, for example, the subreport might have three items and the details five, but if I put it all in the details, I would have fifteen rows, with the first part repeated five times and the second part three times.
The common item appears as a "command field", a "report field". and the Group item. But no matter which of those I link as a subreport parameter, the subreport gets nothing and asks me to enter a value when I try to view the report.
In a more recent version of Crystal Reports you have two options: You can either connect the subreport to a value on the main report via the subreport parameter dialog. or you can pass a Shared Variable between the reports. If you are using the subreport parameter dialog, then the value passed in will be whatever that value is at the time the group is displayed. If the value comes from a detail in that group or from a variable on the main report it shoud pass fine. If the value is something that would be displayed after the group is displayed on the report (going top to bottom) then the value won't be written yet and will be passed to the report as null or blank.
Shared Variables are shared between a report and all of its subreports. If you need to get data from a subreport or pass a single value to multiple subreports, it might be the better option. If the shared variable is changed in the report or a subreport, it'll use the new value in everything after that.
SAP has a good guide on both techniques here:
http://scn.sap.com/people/ashish.bamzai/blog/2011/11/23/passing-values-between-reports-crystal-reports-2008
Bear in mind that Crystal Variables are always populated based on their position in the report and the order they are printed in. If something needs to happen after another group or subreport prints, you'll need to use the WhilePrintingRecords keyword.

Can I assign a value for one parameter

I am using crystal reports 2008. I want to generate a report for which i will get one value from one subreport and i want to pass this value as a parameter so that i can include this value in the sql command.
For eg.
From my subreport i will get customerkey and i want to pass this value in the sql as
{?customerkey}
Sql is 'select card_number from customers where customerkey={?customerkey}'
For this i created parameter in the command and added like this.
But what my problem is this customerkey is getting from subreport(using shared variable).If i get a value customer_key from subreport how will i assign this value to {?customerkey}. I tried like assighning this value but i dont want to popup {?customerkey}this value as a parameter.
Can anyone help? Please
So you want the data shown in the main report to be based on a parameter passed to it from a subreport? I don't think this is possible - the Report Processing Model (described here) states that SubReports are in 'Pass 2', while data retrieval is in 'Pass 1'. This means that the parameter prompt will always appear first.
You might instead be able to have the main report contain TWO subreports, the first of which is used to retrieve the parameter and the second uses it. That can get very messy, especially when dealing with page headers and footers.

Crystal Reports: How do I allow "set to null" when prompting for values to pass to subreports?

I have created a report which links into subreports. I created parameter fields to feed into the parameters of the subreports using subreport links.
If I do not add a subreport link and therefore the subreport is prompting for the value directly it will allow the set to null option. However, if the enter value prompt is being generated from the parameter field I inserted then the set to null option is not displayed.
I have 12 subreports so I can't prompt for the same values 12 times.
I am using Crystal Reports XI designer and not .net
set up formulas with nothing in them (null values) to pass to the subreports
In XI, I've only seen the 'Set to Null' option when the report uses a stored procedure as its data source. Is this the case for your subreport?
Usually, subreports are linked to fields in the main report so that the user isn't prompted repeatedly (once for each time the section that contains the subreport is rendered). If they are linked, the only prompting that will be encountered it that of main report.
Crystal Reports XI parameter fields (created in the UI, not the result of a SP) do not have a 'Set to Null' option. As a result, each parameter will need to have some value.
You may want to have a look at my Crystal Reports: Optional-Multi-Select Parameters posting on how you can add some optional values to your parameters.