Hide or show image based on column values - crystal-reports

I'm working on a report in which I need to show or hide images based on the values of a column. E.G: if the value 18 doesn't exist in the "Details" section, the image 18 must be hidden as described in the attached photo
I tried to use an array in which I inserted the values of the column I need to use. This is the supress expression I tried to use.
shared numbervar array MyArray;
MyArray:=makearray({MyTable.MyColumn});
local numbervar i;
local booleanvar result = true;
for i:=1 to ubound(MyArray)
do
if (MyArray[i] = 17) then
result := false;
result
I realize that the images aren't hidden because I'm working on the Page header and I can only access the first line of the table.

Because you're suppressing the images in the page header, you're limited to simple aggregate functions and won't be able to use variables, running totals, etc.
It's not hard but it is tedious because you'll have to create one new formula for each value.
//#CheckValue1
if {table.value}=1 then 1 else 0
//#SuppressionValue1
// If this evaluates to 'true' anywhere in your report, including the PH,
// you know value 1 does not appear in your report
maximum({#CheckValue1})=0

Related

Crystal Reports - columns line displayed on the last page even there are no records

I have used the following code in a formula in order to count the records:
Shared NumberVar PageofLastField;
If OnLastRecord then PageofLastField := PageNumber;
Also, for page header, I have used the following code in a formula in order to suppress report header if there are no records:
Shared NumberVar PageofLastField;
PageofLastField := PageofLastField;
IF pageofLastfield <> 0 and PageNumber > PageofLastField
THEN TRUE
ELSE FALSE
But still, on the last page, the lines between columns are displayed like a dot (please see printscreen). Can anyone help me? Thanks
Make sure this is not the case with your report.
this happens when you have drawn a line in header section but there is a small portion coming out to the next section. just drag the end point to the same section where the line was started in. This should solve it.

Flag formula field in Page Header based on results

I am trying to flag a Y or N value in the page header if one or more specific values exist in the report result set. (Located in the details section)
It should check to see if "16" exists in the result set. I tried using a running total in the group footer, then setting the formula field in the header to display Y if the count is > 0. But the field only works on the page which contains the 16 in the details section. So if 16 only appears on Page 2, the Page 1 header will incorrectly say N. The field should be Y if 16 appears on any page.
SQL queries aren't possible in formula fields, so is there some way to make this work without one?
I would place this formula "Has16" in your details section and suppress it:
{Table.Field} = "16"
Then place a second formula in your Page Header:
IF SUM({#Has16}) > 0 THEN "Y" ELSE "N"
This will display correctly even on pages that don't contain a 16.

Crystal Reports multiple parameter screens

I am creating a report with crystal reports 2008. My report has 4 parameters that the user must input, lets say: var1, var2, var3, var4. When I open the report it brings up the prompt to enter var1, once entered the user clicks next, and it goes to a second screen to get the next parameter, and so on.
My question is, is there a way to combine all of these to one screen. When the report opens, it has 4 drop downs for the parameters instead of one at a time?
I have thought about (and tried) a parameter that accepts multiple values but could not get it to work for my purposes. I am displaying approx 6 fields related to each parameter selected. SO if var1 is entered there will be 6 additional fields displayed. If it is not selected the area remains empty. Essentially each parameter represents a column to display in the report.
If there is a way to combine the 4 parameter screens that would be great, if you think this can be done using a multi value parameter then that is all I need to know and I will keep at it.
Thank you
Probably did not go about this in the best way but it serves its purpose and thought I would share for future reference. In response to the comments above, the parameters are not linked and I was not using a sub-report.
I ended up splitting the GroupSectionHEader into 4 parts, one for each variable. The report not contained GroupSectonHeader1-5. Each parameter variable had its own section. The user could select the parameter or False from the parameter input dialog. I then used the section expert and for each Group Header in the formula box nex to Suppress (No-Drill-Down) entered isnull({#var#}) or {var#} = " " this is because my variables are strings. This way if the user chose False, the variable would be left black and this formula would pick up on that and hide that section in the final formula.
I am very new at CR so I doubt my explanation is as clear as it could be, nor the most proficient.

How to sum running total field for each group in crystal report?

i have problem in crystall report,
Here is my code following many reference site in google,
// {#reset}
//place in group header
whileprintingrecords;
global numbervar Sum_Cumm_Sum:=0;
// {#increment}
//place in section detail
whileprintingrecords;
global numbervar Sum_Cumm_Sum:=Sum_Cumm_Sum+{#getIP};
// {#display}
//place in group footer
whileprintingrecords;
global numbervar Sum_Cumm_Sum;
Where getIP is Formula,
{#sumKN}/{#sumSKS}
and code in it is running total field with reset on change group,
{#sumKN} is running total field for field KN
{#sumSKS} = is running total field for field SKS
============================================================
I use all this code, but in Sum_Cumm_Sum:=Sum_Cumm_Sum+{#getIP}, I can't get the right value.
Here is my report view:
http://i.stack.imgur.com/CSmsB.png
To the extent I see as you placed in detail section your formula is working correctly, Now you want to see the summation of values in footer then you need to write saperate formula to sum index.... in footer section so that it sumarizes it saperatley.
Either use a manual running total OR a running-total field, not both. By the way, a running-total field only works in a footer section.
A better approach:
{#sumKN} - field is {table.KN}; summarize for all records; reset after change in group
{#sumSKS} - field is {table.SKS}; summarize for all records; reset after change in group
// place in `footer` section
//{#ratio}
// optional
// EvaluateAfter({#sumKN});
// EvaluateAfter({#sumSKS});
{#sumKN} / {#sumSKS}

Auto adjust column size, position if some columns null

I have a simple report with about 20 columns. Some of these columns might be empty. Here's what I am trying to do:
Check if a column is empty.
If it is empty, then readjust the position and size of rest of the columns
to fill up the gap.
Repeat steps 1-2 for every column.
I have some ideas of where to start with but not sure how to move forward.
I can check if a column is empty by :
If DistinctCount({#SomeField}) > 0
I also know that the width and position can be changed by the formatting formulas. But how do I put this together? That is, what logic would run to check and expand the columns and where do I put this logic? Should I be using global variables?
Any suggestion would be helpful.
Thanks
Note: I am using Crystal Report XI
Try this approach:
WhileReadingRecords;
Global booleanVar col1Empty := True;
Global booleanVar col2Empty := True;
...
if not IsNull({dbtable.col1}) then
col1Empty := False;
if not IsNull({dbtable.col2}) then
col2Empty := False;
Then use this global variables in suppres formulas.
Then count how many are not empty can calculate the average column width.