Solved

Crystal report with if statement & Variable not working

Posted on 2010-11-15
7
664 Views
Last Modified: 2012-05-10
Hi,

I have a crystal report (crystal reports basic 2008) thats referencing a microsoft access 2003 query named: " qry_CRYSTAL_REP_FORECAST_PARTCODE" as its data source. Within the report I have a formular field with the below code: The problem is when i try to save and close the formualr the software says: "The remaining text does not appear to be part of the formular" so i guess the syntax i have is incorrect but im not sure what needs to be changed to fix?, please help

numbervar pdact;
numbervar promoqty;

pdact = {qry_CRYSTAL_REP_FORECAST_PARTCODE.PD1ACT}
promoqty = {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_PROMO_QTY}

if {qry_CRYSTAL_REP_FORECAST_PARTCODE.ACTUALS_TO_PD}>0
    then pdact
    else if {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_INCL_BASE}=0 AND {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_PROMO_QTY}>0
    then promoqty
//if criteria not met above then use the below for field
else {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_BASE_QTY} + promoqty
0
Comment
Question by:kevin1983
  • 4
  • 3
7 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 34135255
Some essentials about Crystal syntax..

Every statement apart from the final one must be terminated with a ;
Assignment uses := not just = (which is only used for testing a value).

numbervar pdact;
numbervar promoqty;

pdact := {qry_CRYSTAL_REP_FORECAST_PARTCODE.PD1ACT};
promoqty := {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_PROMO_QTY};

if {qry_CRYSTAL_REP_FORECAST_PARTCODE.ACTUALS_TO_PD}>0
    then pdact
else if {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_INCL_BASE}=0 AND {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_PROMO_QTY}>0
    then promoqty
//if criteria not met above then use the below for field
else {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_BASE_QTY} + promoqty
0
 

Author Comment

by:kevin1983
ID: 34135273
ok thanks for your comments. I tried what you suggested but it says a boolean is required when i try to save and highlights the 0 on this line

 else if {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_INCL_BASE}=0
0
 
LVL 77

Expert Comment

by:peter57r
ID: 34135370
what is the datatype of {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_INCL_BASE}
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:kevin1983
ID: 34135380
The datatype is: Yes/No
0
 
LVL 77

Expert Comment

by:peter57r
ID: 34135410
Then you can't test for 0 you must test for False
0
 

Author Comment

by:kevin1983
ID: 34135443
ok thats great thanks changed to false and seems to work fine now.
(I now have the below)

numbervar pdact;
numbervar promoqty;

pdact := {qry_CRYSTAL_REP_FORECAST_PARTCODE.PD1ACT};
promoqty := {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_PROMO_QTY};

if {qry_CRYSTAL_REP_FORECAST_PARTCODE.ACTUALS_TO_PD}>0
    then pdact

else if {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_INCL_BASE}=false AND {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_PROMO_QTY}>0
    then promoqty
//If criteria not met above then use the below for field
else {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_BASE_QTY} + promoqty
0
 

Author Closing Comment

by:kevin1983
ID: 34135451
Thanks a lot
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question