Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Conditional Formatting Based on Empty Number Field Post Reply Post New Topic
Author Message
JennyB
Newbie
Newbie


Joined: 26 Dec 2012
Online Status: Offline
Posts: 24
Quote JennyB Replybullet Topic: Conditional Formatting Based on Empty Number Field
     Posted: 26 Jan 2014 at 11:41pm
Hi,

I'm having trouble applying conditional formatting based on a blank number field and would really appreciate a bit of help..

We have a product which is classed as gambling, so my report needs to highlight sales where the customer's date of birth makes them under 18, or they haven't supplied a date of birth. I have a DOB field, which is in date format, and an Age formula which is calculated using this formula:

datediff('yyyy',{Command.DOB},Today)-(if datepart('y',Today)>datepart('y',{Command.DOB}) then 0 else 1)

I want the box in which the customer's age appears to be highlighted red when the age isn't 18 plus, and I can get this to work no problem for ages under 18 but I can't get it to work for an empty field.

I've tried:

{@Age}="" - but it complained about ="" that it had to be a number
isnull({@Age}) - doesn't apply the formatting to empty fields
cstr({@Age})="" - doesn't apply the formattiong
len(trim(cstr({@Age})))=0 - still doesn't apply the formatting

So then I tried reversing the formula, colouring the cell red and putting in the formatting to make the background white where {@Age}>=18, and this also clears the formatting from empty {@Age} values so they're not red.

I'm really out of ideas now, does anyone else have any suggestions? It's not a null field, just empty, I think "" would work for a string field but not for a number, and for some reason even converting it to a string doesn't work..

Jenny
IP IP Logged
JennyB
Newbie
Newbie


Joined: 26 Dec 2012
Online Status: Offline
Posts: 24
Quote JennyB Replybullet Posted: 27 Jan 2014 at 12:15am
:/ I've figured out a messy way of doing it, it looks as though if the field value is blank then the field just doesn't appear in the report, so it can't appear formatted and that's my issue? Maybe? :)

So I tried first of all putting the {@Age} field into the text box and formatting that, but for I don't know what reason you can't conditionally format the text colour in a text box, only the borders and infill, and I want it to be red for DOBs under 18, so my slightly messy solution is to put a red bordered box with red infill behind the {@Age} field text box, and now for empty dates of birth the {@Age} field doesn't show so the empty red box behind it is visible. It's a bit messy but it looks ok when the report is run at least..
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 27 Jan 2014 at 4:52am
hmm...I would have thought that in the formatting the cell, in the color tab, you could check the font color and use the background color.

also that:
if isnull({table.field}) then
crRed
else
crWhite

would have thought that would have worked....
been wrong before.
IP IP Logged
JennyB
Newbie
Newbie


Joined: 26 Dec 2012
Online Status: Offline
Posts: 24
Quote JennyB Replybullet Posted: 27 Jan 2014 at 5:02am
:) Yep, I thought that too, but Crystal disagrees. :)

All I can think is that if you drop a field into a report and it's empty then Crystal hides it, so any formatting isn't applied to it. My <18 formatting formulas were working for age values below 18, it was only where there was no age nothing I couldn't get the red highlighting to work.

Very strange, and I couldn't find anything on google about it so I don't know why no one else has had this problem if that's right.. :)
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum