Print Page | Close Window

Report Titles and Multi-Value Parameters

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21261
Printed Date: 01 May 2024 at 4:09pm


Topic: Report Titles and Multi-Value Parameters
Posted By: adavis
Subject: Report Titles and Multi-Value Parameters
Date Posted: 08 Jan 2015 at 3:53am
I always struggle with this issue and have never quite figured out a solution that works well. I'm sure that people here who have been using CR longer than me have already mastered this issue.

I routinely create reports where the user can select one of many values from a parameter. I need a way for the report title to show me all of the values they selected.

For example, on my current report I have a parameter {?Book} which is tied to field {table.book} in my database.

The user can select 1 or a dozen or more values from this field. How do I show all the values they selected in the report title?



Replies:
Posted By: kevlray
Date Posted: 08 Jan 2015 at 4:43am
look up the create a formula and look up the JOIN function.


Posted By: adavis
Date Posted: 08 Jan 2015 at 5:44am
Thanks kevlary. That looks like it will be extremely useful.

EDIT:

I still don't understand how the parameter will be used here. The JOIN function wants a string array. The parameter contains nearly 100 values for the user to choose from and they can choose any of them.


Posted By: DBlank
Date Posted: 08 Jan 2015 at 7:38am
make a formula field as
JOIN(?param,", ")
display in report header
 
or do you mean you are selecting from a list of ints or numeric values and it won't work due to that?


Posted By: adavis
Date Posted: 08 Jan 2015 at 7:44am
Yes, I am using numeric values in this instance.


However, I did try to use the join function with a string parameter as well and was given the same error.


Posted By: DBlank
Date Posted: 08 Jan 2015 at 8:05am
From Ken Hamady's site
http://www.kenhamady.com/form07.shtml - http://www.kenhamady.com/form07.shtml http://www.infosol.com/crystal-reports-displaying-parameter-values/ -
 
 WhilePrintingRecords;
    Local NumberVar Array InputNum := {?AnyNumericPrompt};

    //The last field above is the one you replace with your prompt field
 
    Local StringVar str := "";
    Local NumberVar strLen := Count (InputNum);
    Local NumberVar i;
            For i := 1 to strLen
            Step + 1
            Do (str := str +', '+ ToText(InputNum ,0,''));
 
    str [3 to Length(str)] 
EDIT: link updated to correct link


Posted By: adavis
Date Posted: 08 Jan 2015 at 8:14am
Thanks DBlank.
I had actually read that earlier too, but wasn't able to get it to work right. For some reason it keeps wanting to insert all the possible values in the field and not just the ones the user defines in the parameter, which ends up producing an error stating that the text field has too many characters.

I'll come back to it later. My brain hurts.


Posted By: DBlank
Date Posted: 08 Jan 2015 at 8:20am
copy it exacly and replace the part with your actual numeric parameter name. I think you want to use ?Book...
 
 WhilePrintingRecords;
    Local NumberVar Array InputNum := {?Book};

    //The last field above is the one you replace with your prompt field
 
    Local StringVar str := "";
    Local NumberVar strLen := Count (InputNum);
    Local NumberVar i;
            For i := 1 to strLen
            Step + 1
            Do (str := str +', '+ ToText(InputNum ,0,''));
str [3 to Length(str)] 
 


Posted By: adavis
Date Posted: 09 Jan 2015 at 3:40am
DBlank,

That is the exact formula I tried. When I check the formula for errors, I get an error on InputNum as "this array must be subscripted. For example: Array."

After getting that error, I assumed that I misunderstood the formula and that maybe I was supposed to replace the InputNum text with the number field from my table. I tried that too. The formula looked like this:

WhilePrintingRecords;
    Local NumberVar Array InputNum := {?Route};
    //The last field above is the one you replace with your prompt field

    Local StringVar str := "";
    Local NumberVar strLen := Count ({ub_group.book});
    Local NumberVar i;
            For i := 1 to strLen
            Step + 1
            Do (str := str +', '+ ToText(({ub_group.book}) ,0,''));

The formula, however, returned "True" instead of a list of the values selected from the parameter.

I'm not sure what to try next. I've been working on this for ages it seems. Typically I just get too busy with other things I need to get done, so I just give up and change the title to "selected valued" or something, but I would really like to solve this issue and become a better crystal report writer.

Thanks for your donated time, as always.


Posted By: DBlank
Date Posted: 09 Jan 2015 at 4:07am
I posted the wrong link, it is now corrected to Ken Hamady's site
 
don't forget the last line
 
str [3 to Length(str)] 
 


Posted By: adavis
Date Posted: 09 Jan 2015 at 4:15am
Thanks for the updated link. I have not seen that page before.

I just tried the Multiple Number Parameter method that Ken Hamady provided, as:

WhilePrintingRecords;
    NumberVar Array Input := {?Route};
    NumberVar howmany:= count (Input);

    ToText(Input [1],0,'') +
    if howmany > 1 then ', ' + ToText (Input [2],0,'') +
    if howmany > 2 then ', ' + ToText (Input [3],0,'') +
    if howmany > 3 then ', ' + ToText (Input [4],0,'') +
    if howmany > 4 then ', ' + ToText (Input [5],0,'')


It worked perfectly! *sigh of relief*

Thanks so much for your help and the link. For now, I can start using it. When I have extra time I can dissect it and figure out why it works.



Print Page | Close Window