Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 569
  • Last Modified:

Crystal Rep Conditional Formatting?

I'm hoping someone has done something like this before.

Can I do conditional formatting on a Crystal Report field.  eg.  If the val is negative, make it red, if it is positive, make it black.

If not, is there any way to fake it?
0
PaulHews
Asked:
PaulHews
  • 2
1 Solution
 
AZWolf7Commented:
Absolutely. Select the field you want to format this way, and right click. Next, select Format Field from the popup menu.

Let's call the field Amount.

Go to the font tab of the format menu.
Now, next to the font color, you will see a button with x+2 on it. Click it, and you will be able to add conditional code to the formatting.

You should be in the Format Formula Editor now. type an 'if ', then select the field (in this case, Amount) from the 1st column. You should see something like:

if {MyTable.Amount}

then continue to set you settings like:
if {MyTable.Amount} > 0 then
    black
else
    red


I am not sure the exact syntax for the color. You might have to change the code to say:
{MyTable.Amount}.Black
or
{MyTable.Amount}.Color = Black
0
 
Brendt HessSenior DBACommented:
I have a cheat that works.

Create two formulas that output your number using ToText to format it as a string.  The formulas should be like this:
----------------
If {MyDb.MyNumber}>=0 Then
ToText ({MyDb.MyNumber}, 2)
Else
""
-------------
and
----------------
If {MyDb.MyNumber}<0 Then
ToText ({MyDb.MyNumber}, 2)
Else
""
-------------

Now, place the formula boxes over each other, format one red, one black, and Voila!
0
 
Brendt HessSenior DBACommented:
Note that my version of Crystal does not support conditional formatting of fonts and font colors.  If yours does, AZWolf7's answer is much more elegant.  
0
 
PaulHewsAuthor Commented:
Thank you both.  Fortunately, Crystal Version 6.0 supports this feature, so I'll give the points to AZWolf7
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now