4 Replies Latest reply: Jul 25, 2016 4:41 PM by Sunny Talwar

# If statement not working properly

Hello, my If statements are not working properly. The idea behind this is that when one clicks on a Code in the Listbox, it will narrow down the results to the ones containing that code. However, if no Code is selected in the listbox, it will display the Sum of the values.

Currently, if the code does not match 1 through 8, it is by default just selecting Code 1 and using those values, rather than the sum of all values as I want it to.

Here is my code:

if(Code = '1', Montreal,
if(Code = '2', Gagetown,
if(Code = '3', Valcartier,
if(Code = '4', Meaford,
if(Code = '5', Petawawa,
if(Code = '6', [Edmonton Spares],
if(Code = '7', Edmonton,
if(Code = '8', Wainwright,
(
Sum(Montreal + Gagetown + Valcartier + Meaford + Petawawa + [Edmonton Spares] + Edmonton + Wainwright))))))))))

Any help is greatly appreciated.

Thanks,

Alec

• ###### Re: If statement not working properly

surround all expressions with sum()

if(Code = '1', sum(Montreal),
if(Code = '2', sum(Gagetown),
if(Code = '3', sum(Valcartier),
if(Code = '4', sum(Meaford),
if(Code = '5', sum(Petawawa),
if(Code = '6', sum([Edmonton Spares]),
if(Code = '7', sum(Edmonton),
if(Code = '8', sum(Wainwright),
(
Sum(Montreal + Gagetown + Valcartier + Meaford + Petawawa + [Edmonton Spares] + Edmonton + Wainwright))))))))))

• ###### Re: If statement not working properly

Thank you for your reply. Unfortunately, that did not fix the issue though. Do you have any other ideas?

Thanks,

Alec

• ###### Re: If statement not working properly

It would be easier if you post a sample of you app