Crystal Reports Training by Ken Hamady, MS, Reporting and Training Nationwide On Location TrainingPublic ClassesIndividual TrainingIntroductory Course OutlineAdvanced Course OutlineFormula ExamplesNewsletter Back IssuesMy BlogResource LibraryConsulting ServicesSupport ServicesContact InformationLinks to third party productsBack to main pageMy Credentials
Free Crystal Reports formula examples from KenHamady.com


To learn the techniques used in these formulas get:


The Expert's Guide to Crystal Reports Formulas
and
 Expert Techniques for Crystal Reports I, II & III

PDF exPLODE

Appending a List of Details into One Line:

How do you get a list of detail strings to print on one line?  So that a list of detail items like:

    ItemA
    ItemB
    ItemC

prints out as one line like:

    ItemA, ItemB, ItemC

The solutions requires three formulas, and assumes that the items are within an existing group on the report:

1) In the Group Header place the @reset formula:

    WhilePrintingRecords;
    StringVar chain := '';
    NumberVar ChCnt := 1


2) On the Details place the @Accum formula, putting your field into the second line:

    WhilePrintingRecords;
    StringVar Item:= {Your.Field}; // place your field in place of {Your.Field}
    StringVar Chain;
    NumberVar ChCnt;

    if ChCnt = 1
    then (ChCnt:= 2; chain := Item)
    else
    if Length(Chain) + Length(Item) > 254  //see note about this number below
    then Chain := Chain else
    chain := chain + ', ' + Item


3) On the Group Footer place the @Display formula:

    WhilePrintingRecords;
    StringVar Chain


**Important Note.  A string formula cannot output more than 254 characters in versions before v9.  So if your items add up to over 254 characters this formula will not print them all.  It will only print the items that fit within the first 254 characters.  You can select any number lower than 254 to stop the accumulation earlier.  To get a longer string in versions before v9 you could create a second parallell set of formulas that picks up where this one leaves off.   If you are using v9 or later you can replace the 254 limit with any number up to and including 64,000 which is the new limit on the output of a string formula.