I've never had a good way to prevent widowed Group Headers on a Crystal Report. By "widowed Group Header", I mean a report where the last thing on a given page is the next Group Header and there isn't any room for details, so it's just the header by itself.
If you use the "Keep Together" options of either the Section Expert or the Change Group dialog then you don't get any widows but you get big chunks of blank space, so it's not the answer.
The best answer I found for my needs is described here as "Method Two".
Like most things, it's pretty simple once you know the answer!
You stick the first detail of the group into the Group Header and then set the Group Header to have "Keep Together" turned on in the Section Expert. Now you will always have at least one detail with the Group Header.
But that would leave you repeating your first detail, right? So to deal with that part, you put a suppression formula into the Detail section like this:
//This formula
conditionally suppresses the first record of the Details //section.
//Replace
{database.field} with the field by which you are grouping.
WhilePrintingRecords;
Onfirstrecord
or {database.field} <> Previous({database.field})
It's a thing of beauty!
THanks.
Posted by: jasbir | March 08, 2012 at 09:23 AM
Thanks for confirming this is the only method for getting this result.
While this works well, there seems an issue if you also want the Group Header to repeat at the top of each page as then the first detail record appears twice.
I haven't figured out how to (a) have a group header repeat at the top of the page and (b) prevent a widowed group header and (c) NOT introduce all that whitespace by using either Keep Together or New Page Before...
Is there a way of suppressing the first detail record on a page if it's also the first detail record of a group? I suspect not.
Crystal Reports really needs one more option to prevent widowed group headers by just having a "Keep Together with first child"... I think that would solve it...
Going off now to submit that suggestion to Crystal :P
Posted by: Evahn | April 26, 2012 at 09:12 PM
Ahh kk - nevermind. Just figured that one out finally.
You need to also setup a global variable which is reset to zero in the page header and incremented by one in the detail.
Then you just extend the Suppress formula for the detail:
Onfirstrecord or {database.field} <> Previous({database.field}) or (PageRecCount=1)
(Tho I still think a button titled Keep Together with 1st Child would be a better solution hehe)
Posted by: Evahn | April 26, 2012 at 10:17 PM