Avatar of kevin1983
kevin1983
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Crystal report with if statement & Variable not working

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
Crystal ReportsSQL

Avatar of undefined
Last Comment
kevin1983

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
peter57r

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kevin1983

ASKER
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
peter57r

what is the datatype of {qry_CRYSTAL_REP_FORECAST_PARTCODE.FORECAST_1_INCL_BASE}
kevin1983

ASKER
The datatype is: Yes/No
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
peter57r

Then you can't test for 0 you must test for False
kevin1983

ASKER
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
kevin1983

ASKER
Thanks a lot
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.