Retrieve record count of subreport in Crystal Reports

You can create a formula field on the subreport which contains a shared variable. In the formula you'll set the shared variable to the value of the rowcount field in the subreport.

Then in your main report you will need to create a formula with a shared variable that has the same name as the subreport and then return the value of the shared variable.

answered Aug 12, 2009 at 21:30 4,697 3 3 gold badges 30 30 silver badges 35 35 bronze badges
  1. Put this formula in your subreport. You can suppress it from display if you like. whileprintingrecords;
    Shared numbervar SubRecordCount:=(however you want to count the records in the report);
  2. Put this in your main report. Again, this can also be suppressed. whileprintingrecords;
    shared numbervar SubRecordCount;
    SubRecordCount
  3. Use the formula name for #2 for whatever calculations you need.
    IMPORTANT: Due to the fundamental logic of Crystal, you can only use this field if it is BELOW it's subreport.
    Also, as for counting the records in the subreport, I recommend a running total at the bottom of it.
answered Aug 13, 2009 at 17:21 11.7k 20 20 gold badges 65 65 silver badges 102 102 bronze badges

here you can retrive sub report count from code side

CrystalDecisions.CrystalReports.Engine.ReportDocument RepDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); RepDoc.Load(ReportName); int IntRepCount = RepDoc.Subreports.Count; 

pass this count to your report