Solved

Crystal report with if statement & Variable not working

Posted on 2010-11-15
7
668 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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