Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple if/then in one formula

Status
Not open for further replies.

ForMe2

Technical User
Jan 16, 2007
15
US
How do I enter multiple conditions in one formula? Here is what I have. It only uses the last if/then in the formula.

if CStr({tbl_Item.Amount2})=" " and ({tbl_Promo.Scan}> {tbl_Item.Amount}) then
formula=({tbl_Item.Amount}*{tbl_Qty.Qty})
end if
If{tbl_Item.Amount}=CCur(0.00) then
formula=(({tbl_Promo.Scan}*{tbl_Qty.Qty})*CDbl ({tbl_Item.Amount2}))
end if
If CStr({tbl_Item.Amount2})=" " and ({tbl_Promo.Scan}<{tbl_Item.Amount}) then
formula=({tbl_Promo.Scan}*{tbl_Qty.Qty})
end if
 
You had 3 independent If statements there and it returns the results of the last one.
Try it this way:

if CStr({tbl_Item.Amount2})=" " and ({tbl_Promo.Scan}> {tbl_Item.Amount}) then
formula=({tbl_Item.Amount}*{tbl_Qty.Qty})
else
If{tbl_Item.Amount}=CCur(0.00) then
formula=(({tbl_Promo.Scan}*{tbl_Qty.Qty})*CDbl ({tbl_Item.Amount2}))
else
If CStr({tbl_Item.Amount2})=" " and ({tbl_Promo.Scan}<{tbl_Item.Amount}) then
formula=({tbl_Promo.Scan}*{tbl_Qty.Qty})
end if

~Brian
 
Thank you, but I tried that and it still only read the last if/then statement.
 
I'd split out each test as a boolian, i.e.
Code:
CStr({tbl_Item.Amount2})=" " and ({tbl_Promo.Scan}> {tbl_Item.Amount})
This should say True or False if you put it beside your data, or in an extra detail section under your line. You may find your tests are failing.

I also don't see why you need formula= or end if. Is this crystal or SQL?

It also helps to give your Crystal version - 8, 8.5, 9, 10, 11 or whatever. Methods sometimes change between versions, and higher versions have extra options.


[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
This is a SQL formula, but I can use the Crystal. Which one would you suggest?
 
I use Crystal because I know it better. It's probably easier to write.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top