cancel
Showing results for 
Search instead for 
Did you mean: 

SubReport: Dynamic Build Record Selecton Formula based upon the values of the sub report links

caresreports
Explorer
0 Kudos

I have a Crystal Report with a sub report.

The sub report has the same where clause as the main report. but shows some additional data based upon system configuration. I went this way because I don't want to maintain two report files.based upon how a system is configured. I rather just show a sub report when necessary. (its DRY: Don't Repeat Yourself)

The where clause for the main report is built at at runtime based upon what inputs the user has given and the application uses the crystal report SDK to set the RecordSelectionFormula on the report document object.

I'd like to give the sub report this same where clause. The Report Selection Formula builder needs to see a boolean clause. Passing in the predefined RecordSelection in the from main report to the sub report won't work as I get the warning the "Record Selection Formula Editor needs to see a boolean. "

See how the application can set the RecordSelectionFormula on the main report, I suppose I can pass the where clause to the sub report but just curious, can the Crystal Report Record Selection Formula builder do the following

VIEWNAME.Field = {input}

if (input 2 = 1) then

AND VIEWNAME.FieldTwo > ("some text")

if (input3 = A) then

AND VIEWNAME.FieldThree > ( a number)

Suggestions

DellSC
Active Contributor
0 Kudos

I changed the tag on your question to "SAP Crystal Reports, version for Visual Studio", which is the tag for questions about how to do things in the .NET SDK. The "SAP Crystal Reports" tag is for questions about report design or how to use the Crystal desktop software.

-dell

Accepted Solutions (1)

Accepted Solutions (1)

DellSC
Active Contributor
0 Kudos

Best practice is to not use If statements in the selection formula. Crystal can't always pass them to the database where they're processed more efficiently and will instead bring all of the data into memory and filter it there.

I would re-write the selection formula like this:

VIEWNAME.Field = {input}

AND

(
  input 2 <> 1
  OR
  VIEWNAME.FieldTwo > ("some text")
)
AND
(
  input3 <> 'A'
  OR
VIEWNAME.FieldThree > ( a number) )

Secondly, I would create parameters in the report for input, input2, and input3. Use the parameters as the link from the main report to the matching parameters in the subreport. Then set the parameters in your code instead of building the RecordSelectionFormula. See here for information about how to set parameters in your code.

-Dell

Answers (0)