Crystal report forumlas

dreamtime

Active member
Joined
May 13, 2005
Messages
26
Programming Experience
1-3
*Resolved* Crystal report forumlas

I am so close to my reporting needs...but....

I am now having trouble with suppression forumla.

I would like to examine a field in the database attached to Crystal Reports and suppress a report section if the field equates to a certain value. I have no trouble with this using ...

if not({myreports.subject} = "Art") then true

(the suppress box is ticked)

I would like to extend this to multiple values but I cannot get it to work.

I have tried....

1)
if not({myreports.subject} = "Art") then true else
if not({myreports.subject} = "DT") then true

2)
if not({myreports.subject} = "Art") or
not({myreports.subject} = "DT") then true

and various other types of if, else, or loops.

None seem to work.

Any ideas would be appreciated.
 
Last edited:
Can you give some explanation, of what you are expecting to get, and what you actually make it to be true ... of course it is boolean data type but you must clearly say that within formula ... i.e.

if condition then myBool = True

or:
If Not ({Table.Field} = "Kulrom") And Not ({Table.Field} = "Kulrom2") then
"This is correct but there are other ways ... "

If {Table.Field} <> "Kulrom" Or {Table.Field} <> "Kulrom2" Then
"This is also correct but there are other ways ... "

Cheers ;)

added: btw, you cannot interrupt an if statement where it's not allowed ... for instance you can writte one row if statement without close it by End If

if statement = true then messageBox.Show("blah") 'it is correct but not conventional way cuz of its bad Synoptic.

but note that you cannot interrupt next statement like this:

if statement = true then or
statement = false
messageBox.Show("blah")
End If

even if you close it with end if statement you will still get an error msg.
 
Last edited:
I don't use Crystal Reports so I can't comment on that specifically, but it looks to me like your logic is flawed. I'm not 100% sure what you're trying to achieve but I'm guessing that your example is trying to tick your suppress box if {myreports.subject} is not equal to "Art" and not equal to "DT". Can I recomment not using the "Not" operator with the "=" operator if possible. It can be confusing so it is best to use "<>" (not equal) if you can. I think you want:
VB.NET:
If {myreports.subject} <> "Art" AndAlso {myreports.subject} <> "DT" Then
This is VB code, obviously. As I said, I don't use Crystal so I'm not sure if the code examples you gave are in Crystal itself rather than VB. If I've misinterpreted your intention then please post back and I'll try again.
 
Thank you for your replies. I will try some of the suggestions you have put down. Here is some further info as requested.

The result I am trying to get is to show one section of a report for one group of values (eg. Art, DT, English) and to show another section for a second group (eg. Maths, Science). This value is {myreports.subject}.

I have successfully made this work for one subject using...

if not({myreports.subject} = "Art") then true.

The suppress box is ticked so if the field is 'Art', then the first section is not suppressed. If the field is 'Maths', then the first section remains suppressed and the second section shows.

I think I will switch to <> and try

If {Table.Field} <> "Kulrom" Or {Table.Field} <> "Kulrom2" Then

...as suggested.

I believe I tried the similar...

If Not ({Table.Field} = "Kulrom") or Not({Table.Field} = "Kulrom2") then true

... last night but I may have gotten it wrong or split it up incorrectly.

I do not get a syntax error when I exit the forumla editor - its just that the report never works when the additional values are present (sections just remain suppressed).

Ideally I wish to check for the existence of 'Art' 'in' the field and show based on that (ie. Field may actually be 'Art Year 4').

I tried...

if Not({myreports.subject} in "Art") then true

I will get my laptop out now to test the suggestions and let you know the outcome.
 
dreamtime said:
If {Table.Field} <> "Kulrom" Or {Table.Field} <> "Kulrom2" Then
This is where I think your logic is flawed. The statement I have quoted will be true no matter what the value of Table.Field. If it is "Kulrom" then the second subexpression is true so the whole expression is true. If it is "Kulrom2" then the first subexpression is true so the whole expression is true. If it is anything else then both the subexpressions are true and the whole expression is true. There is no possible value for Table.Field that can make that expression false. If you want it to be true only when Table.Field is not "Kulrom" or "Kulrom2" then you need to use one of the following two expressions:
VB.NET:
If {Table.Field} <> "Kulrom" And {Table.Field} <> "Kulrom2" Then
or
VB.NET:
If Not ({Table.Field} = "Kulrom" Or {Table.Field} = "Kulrom2") Then
 
Thank you jmcilhinney.

I am going to need to meditate zen-like on some of these logic statements!!

You are correct, the statement...

If Not ({Table.Field} = "Kulrom" Or {Table.Field} = "Kulrom2") Then

...worked a dream.

I appreciate your help.
 
Back
Top