Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Counting records in a subreport Post Reply Post New Topic
Author Message
Dyrge
Newbie
Newbie
Avatar

Joined: 06 Aug 2007
Online Status: Offline
Posts: 7
Quote Dyrge Replybullet Topic: Counting records in a subreport
    Posted: 18 Aug 2007 at 5:57am
In my report, I have a subreport that displays the records from a table. On the main report before the subreport, I need to display the number of records that the subreport displays. The count function doesn't seem to do what I need. I figured a running total would work, but since I am displaying the records in a subreport, I can't figure out how to this. Anyone know how to do this?
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 18 Aug 2007 at 6:57am
You should be able to do the count in the subreport.  Once that is done pass the value to a shared variable. Then use the shared variable as the means to display it on the main report.
 
It might look something like this
 
subreport - create a new formula
 
WhilePrintingRecords;
shared numbervar x;
x := 0;
x := Count{datafield name};
x;
 
New main report formula
 
WhilePrintingRecords;
shared numbervar x;
x;
 
The idea is the count occurs while the records are being printed then the main report reads the count. Depending on groupings,  etc., you need to keep in mind number of passes CR makes in creating reports and subreports to get the proper placement of the formula.
 
Hope this helps.
 
Regards,
 
John W.
IP IP Logged
Dyrge
Newbie
Newbie
Avatar

Joined: 06 Aug 2007
Online Status: Offline
Posts: 7
Quote Dyrge Replybullet Posted: 20 Aug 2007 at 12:40am
I tried your code and I keep getting 0 for the count when it should be 1. Is it possible to use the EvaluateAfter for the formula field in the main report and set it to evaluate after the formula field in the subreport?
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 20 Aug 2007 at 9:13am
I would give it a try. If you are getting the correct count in subreport you should be able to pass it through the shared variable.
 
Another way, perhaps less attractive but would work is to add a command object in the main report database expert that has the sole purpose of counting the records  in the subreport. Essentially you create a Select Count(datafield) from table where (enough conditions to give you the accurate count). Then place that field in the report where you want it.
 
Hope this helps. Perhaps Dell (hilfy) will  see this and be able to offer up a better solution.
 
 
Regards,
 
John W.
 
IP IP Logged
Dyrge
Newbie
Newbie
Avatar

Joined: 06 Aug 2007
Online Status: Offline
Posts: 7
Quote Dyrge Replybullet Posted: 20 Aug 2007 at 10:25pm
I will try the EvaluateAfter if I can get it to work. Every time I have tried before,  I get some error about missing ) when it is in there.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.015 seconds.