Only show first 2 records in detail section of a subreport

xcao
xcao used Ask the Experts™
on
I have a crystal report that has a sub report.

In the subreport I would like in detail section only show the first 2 records, how can I achieve that.
if more than 2 records, all the other records won't be displayed.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
In the section expert for the detail section of the subreport, in the conditional suppression button set the rule as

recordnumber>2
Note that if you use suppression, the subreport will still read all of the records, but only output the first two.  If the subreport isn't reading too many records, that may be fine.  But if the subreport is reading thosands of records every time it's run, that could be a problem.  If there is something in the data that you can use to identify the first two records in the record selection in the subreport, that would be much more efficient.  I'm guessing that there isn't anything like that, but I wanted to mention it, just in case.

 James
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Agree.  You could try using a TOP 2 selection in the subreport without any sorting of the records.

mlmcc
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Author

Commented:
Thank you, my case is in the subreport I want to pull student guardians, usually is 2, the most is around 4, if I use the recordnumber>2 suppress, it works OK if there are more than 2 guardians, but if there is only one guardian, how can I handle this, I would still like to leave two rows on the form, one is the guardian 1 preloaded data, the second row I would like to leave it blank for parents to fill in .
How can I handle this?

thanks
In your subreport, you would group the report by the field that links it to the main report.
Lay out the group footer the way you want the blank row to appear.
Add a summary to the group footer which counts the records in the group.
Then use a conditional suppression formula on the group footer, so that it only prints if the record count is 1.

So suppress when:
count(.......) >1

Author

Commented:
should I use count()>1 or recordnumber>1, cannot figure out the difference
You have to specify the summary field which contains the count of records in the group.
You can pick it from the list of report fields in the formula editor. But do not type it - what you pick is NOT what goes into the formula.

Author

Commented:
I use recordnumber in the group footer, it seems working correctly

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial