crystal subreport field is blank in main report footer - crystal-reports

I have a subreport that has one group and has the following formula in Group Header 1
WhilePrintingRecords;
Shared StringVar TaskSubject := {activity_trans.subject}
My main report has the following formula in Group Footer 1
WhilePrintingRecords;
Shared StringVar TaskSubject;
TaskSubject
When I drill into the detail section of my main report the field shows a value in the GF1 section but when I preview the main report the field is blank.

The problem with putting the formula in the Group Header is that you only get one record for the formula, which usually is the first record available. If that first record is blank, then you will see no data. Your formula is correct, but there may be an issue with the way you have structured your report or the data you are trying to display.

Related

Crystal Report Shared NumberVar from sub-report to main-report. Why first record display 0 value?

I need to get Shared NumberVar from Sub-Report to Main-Report but first record display 0 value in this Group footer (My value display on Group footer) value do not match in same line
I need to display correct value in same line.
Please help.
Sub-Report
WhilePrintingRecords;
Shared NumberVar qty;
qty:= sum({OE.QTYSOLD});
Main-Report
WhilePrintingRecords;
Shared NumberVar qty;
Main report formula getting a subreport shared variable value must be in a section BELOW the subreport section. This is because section formulas are evaluated before subreports in the same section.
So split the section or move the subreport to a higher section.

Duplicates in sub-report

I have crystal report with a sub report in it. The sub report is displaying duplicates. To avoid that I used below formula.
{table.IDField} = previous({table.IDField})
Now, duplicates are removed but I have sum of the field in the footer. All the duplicate values are added to the sum. Is there a way that I can select distinct records in the sub report?
I followed below steps to solve this issue.
Created a group on the IDField
Moved all the fields from detail section to the above group header.
Suppressed the detail section.
Created the below formula and placed it in group header. I have supressed this because I didn't have to display this.
whileprintingrecords;
numbervar totalOfIDField := totalOfIDField + {IDField};
"";
Created a formula to display the above field (totalOfIDField).
whileprintingrecords;
numbervar taotalOfIDField;
This should be placed in the corresponding Group Footer.
Created a formula to reset the totalOfIDField each time group changes. Included this in the Main Group Header.
whileprintingrecords;
numbervar totalOfIDField := 0;

Crystal report subreport displays alternative text when no records returned in subreport

How to display alternative text when no records returned in subreport?
e.g. if there is no record returned in subreport, i want to display '-'
thanks
You need 2 details sections in your report. In 1 put the what ever you want to show when you have records. Right click the same section and select Section Expert.... Check the Suppress Blank Section checkbox so this space used by this section is suppressed when there is nothing to show. In the other details section add a formula that prints what you want to display when there are no records. In your example this would be "-". Create another formula for counting records and name it RecordCount.
WhileReadingRecords;
NumberVar RecordCount := RecordCount + 1;
Place this formula in the details section of the report and suppress it. It is not important which details section you place it in. Finally, right click the same section that will show when there are no records select Section Expert.... Click the formula button for the Suppress (No Drill-Down) and add this formula...
Not Isnull ({#RecordCount})
You can see that you are only checking if the formula itself is null so the code in the formula is not all that important, but I like to make it useful in case I want to use it elsewhere in the report.
Now when you have records the second details section is suppressed and the first details section shows your data. When you have no records it is reversed and the second details section is shown while the first details section is suppressed.
Assuming you want the "-" to appear within the subreport, put it in the subreport's report header or report footer section and set the visibility of either the text item or the section (depending on whether you want the section to appear regardless of how many records are returned) to be conditionally suppressed on a formula like:
Count ({Table.Field})>0
This is one way to do it. Create a shared variable that tracks row count of sub report and then displays a text field if that count is zero.
From memory on shared fields it goes something like this... create a formula field with this code and then put that formula somewhere on the report. You can hide it so it's not visible.
shared numberVar rowcount := 0;
To set the shared variable equal to the number of rows in the sub-report. Do the same thing, (create a formula field in the sub report) but like this:
shared numberVar rowcount := <number of rows>;
There is code all over on different ways to get number of rows.
Then back on your main report make a text field that contains "-" and have it suppressed when the shared variable is greater than 0. You can also right click the subreport and set it to suppress when blank if you want.
Finally, make sure and put the text field "-" (with the suppress function) below the sub-report because Crystal won't know how many records are in the sub-report until after it tries. Crystal is funny that way.
See Crystal Reports: Display a Message When Report Has No Data
The Best way I can Suggest You is to play around with crystal reports for solutions, from your question You want to display "-" when no data present, So here is the answer:
First:1 Create an New Formula In the Sub-Report and Use editor and write the following Formula:
shared stringvar myvar;
if isnull({Id_colounm_name}) then myvar := "-"
else myvar:="+"
Note: here Id_coloumn_name is the row member which can decide the records are empty.
Second 2:
Save the formula and create a new page header section and suppress it, then add this formula to the newly created and suppressed section.
Third 3:
Go to the main report and create a new Formula, use the editor to write the following formula:
shared stringvar disp;
Save and close the formula editor.
Fourth 4:
Now insert a section below the section in which your crystal report lies.
Now go to section expert by right clicking on the section
and select formula icon right after the "Suppress" and add the following formula:
shared stringvar myvar;
if myvar <> "-" then true
else false
Save and close the formula and select the icon right after "Suppress Blank Section" and add the following formula:
shared stringvar myvar;
if myvar="+" then true
Save and close the formula, Now add the formula created in the main report to the newly created section. Save it.
Fifth 5:
Right click on the sub report and select "format object" and then select "Subreport" tab and check "Supress Blank Subreport"
and then right click on the section where your sub report lies and then goto "section expert" and then check "supress blank section"
Thats all you can do, Now run the report and check if its working or not
Note Note Note: The section containing the sub report should not contain any other text of other fields and the section containing the formula in the subreport has to be supressed and section containing the formula in the main report doest have to be suppressed.
Hope it helps
Thanks and Regards
Srikanth

Store sub report fields in array

Hi I want to store sub report fields per page into an array and print that array inside the report footer in main report. Any clue guys ?
If you're talking about only a few fields, then I'd recommend a shared variable taking the data back to the main report.
If it's alot of data, then you should make another subreport in the main report's footer and calculate all your data there.
Edit
Well, you asked, so here's how:
In your main report's footer, create a formula (call it FooMain) with this code:
whileprintingrecords;
shared stringvar MyLittleVar;
In your subreport, create a formula (call it FooSub) with this code:
whileprintingrecords;
Shared stringvar MyLittleVar:="This is from the subreport";
Preview your report. In the footer, the FooMain formula should display "This is from the subreport". Use FooMain in whatever calculations in the main report. Due to fundamental design aspects of Crystal, this will only work if FooMain (and any formulas that reference it) is below the subreport it is getting data from.

Crystal Reports: global variable running total not displaying in header

Using Crystal Reports I'm trying to display the running total of a database field in the header where all the labels are.
I've attempted to do this by placing the running total (RTversion) into a formula field with the following:
Shared stringvar CurrentVers;
CurrentVers := {#CurrentVers};
and then in the page header section I have the following:
Shared stringvar CurrentVers;
EvaluateAFter({#currentVers});
CurrentVers;
with {#CurrentVers} running the 1st largest number.
Is this incorrect?
Update: The goal is to display the latest version in the header near the labels to show what the current verseion is for comparison.
Running-Total Fields, in my experience, only work in the footer sections.
You will need to create a manual running total.
Add a formula field to the Details section that populates a Global variable with whatever you are trying to capture. Something like:
//use WhileReadingRecords if the values can be gathered as the report pulls in values from the database. Otherwise, use WhilePrintingRecords.
WhileReadingRecords;
Global Stringvar CurrentVers;
//logic here to capture what you want
CurrentVers:=...
Add another formula field to the Header section. Add these two lines to it:
WhilePrintingRecords;
Global Stringvar CurrentVers;
Create a formula like this
formula = Count ({Field to count},{GroupFieldName})
and place it in group header section.
I figured it out..
I had to add a subreport to the main report. I copied the main report and renamed it as a subreport. In the subreport, I added a shared variable and then passed it to the main report. The trick is to place the subreport in the same group header, but a separate section above the section that needs to be suppressed. I actually added the following sections:
New section (same group-I placed subreport here; do not suppress)
New Section (same group - I placed shared variable value here; do not suppress)
Original Section (same group that has a header I need suppressed based on a running total)
If {#CurrentVers} is a regular running total field, you should be able to place it in the page header directly rather than resort to an additional formula. I don't see the need for either formula field here, unless there's something unusual in the composition of {#CurrentVers} and a 'largest number' running total shouldn't require anything out of the ordinary.
You can solve this with just one formula field:
WhilePrintingRecords;
// Enter logic here e.g.
// maximum({mytable.myfield});
The WhilePrintingRecords; forces the formula to not be evaluated until all records have been read from the database, and therefore the formula field will display the correct result even if placed in a header.
The key I found is that the formula field being passed needs to be placed on the subreport. I placed mine in the footer then suppressed it.