If statement not displaying text if conditions not met

R

Ruth

I want to do a calculation which calculates selling price from either Margin
% or Margin £ and if there is nothing in either field then I want to display
the text "no margin". I have tried the following formula:-

Sell Ex VAT: IIf([Margin %] Is Not Null,[Cost Price]+([Margin %]*[Cost
Price]),(IIf([Margin £] Is Not Null,[Cost Price]+[Margin £],"no margin")))

However, if there is nothing in either field, then it returns #Error.

Anyone got any ideas?
 
D

Duane Hookom

I try to create expressions that return only a single data type. Your
expression might return a number or possibly a string. I would replace the
"No Margin" with Null. You can then use the format property of your text box
to display "No Margin" for all Null values.
 
R

Ron2006

I want to do a calculation which calculates selling price from either Margin
% or Margin £ and if there is nothing in either field then I want to display
the text "no margin". I have tried the following formula:-

Sell Ex VAT: IIf([Margin %] Is Not Null,[Cost Price]+([Margin %]*[Cost
Price]),(IIf([Margin £] Is Not Null,[Cost Price]+[Margin £],"no margin")))

However, if there is nothing in either field, then it returns #Error.

Anyone got any ideas?

Change the format of the is null condition:

Sell Ex VAT: IIf(not isnull([Margin %]),[Cost Price]+([Margin %]*[Cost
Price]),(IIf(not isnull([Margin £]),[Cost Price]+[Margin £],"no margin")))

or alternately:

Sell Ex VAT: IIf(isnull([Margin %])=false,[Cost Price]+([Margin
%]*[Cost
Price]),(IIf(isnull([Margin £])=false,[Cost Price]+[Margin £],"no margin")))



Ron
 
R

Ruth

yes this does work - I guess its because its returning a number as opposed to
some text.......

mscertified said:
What happens if you change "no margin" to 0 (zero). Does it then work?

-Dorian

Ruth said:
I want to do a calculation which calculates selling price from either Margin
% or Margin £ and if there is nothing in either field then I want to display
the text "no margin". I have tried the following formula:-

Sell Ex VAT: IIf([Margin %] Is Not Null,[Cost Price]+([Margin %]*[Cost
Price]),(IIf([Margin £] Is Not Null,[Cost Price]+[Margin £],"no margin")))

However, if there is nothing in either field, then it returns #Error.

Anyone got any ideas?
 
R

Ruth

Replaced "No Margin" with Null and yes this does work - it does not display
anything in the column. How do I change the format to display "No Margin"
for Null values? I'm using the formula in a query which feeds into a form.

Duane Hookom said:
I try to create expressions that return only a single data type. Your
expression might return a number or possibly a string. I would replace the
"No Margin" with Null. You can then use the format property of your text box
to display "No Margin" for all Null values.

--
Duane Hookom
Microsoft Access MVP
If I have helped you, please help me by donating to UCP
http://www.access.hookom.net/UCP/Default.htm


Ruth said:
I want to do a calculation which calculates selling price from either Margin
% or Margin £ and if there is nothing in either field then I want to display
the text "no margin". I have tried the following formula:-

Sell Ex VAT: IIf([Margin %] Is Not Null,[Cost Price]+([Margin %]*[Cost
Price]),(IIf([Margin £] Is Not Null,[Cost Price]+[Margin £],"no margin")))

However, if there is nothing in either field, then it returns #Error.

Anyone got any ideas?
 
R

Ruth

Thanks for your help, but I can't get this to work it still returns #Error.

Ron2006 said:
I want to do a calculation which calculates selling price from either Margin
% or Margin £ and if there is nothing in either field then I want to display
the text "no margin". I have tried the following formula:-

Sell Ex VAT: IIf([Margin %] Is Not Null,[Cost Price]+([Margin %]*[Cost
Price]),(IIf([Margin £] Is Not Null,[Cost Price]+[Margin £],"no margin")))

However, if there is nothing in either field, then it returns #Error.

Anyone got any ideas?

Change the format of the is null condition:

Sell Ex VAT: IIf(not isnull([Margin %]),[Cost Price]+([Margin %]*[Cost
Price]),(IIf(not isnull([Margin £]),[Cost Price]+[Margin £],"no margin")))

or alternately:

Sell Ex VAT: IIf(isnull([Margin %])=false,[Cost Price]+([Margin
%]*[Cost
Price]),(IIf(isnull([Margin £])=false,[Cost Price]+[Margin £],"no margin")))



Ron
 
O

Ofer Cohen

You can use the Nz function to replace the Null with the String

Nz(YourExpresionHere,"No Margin")

--
Good Luck
BS"D


Ruth said:
Replaced "No Margin" with Null and yes this does work - it does not display
anything in the column. How do I change the format to display "No Margin"
for Null values? I'm using the formula in a query which feeds into a form.

Duane Hookom said:
I try to create expressions that return only a single data type. Your
expression might return a number or possibly a string. I would replace the
"No Margin" with Null. You can then use the format property of your text box
to display "No Margin" for all Null values.

--
Duane Hookom
Microsoft Access MVP
If I have helped you, please help me by donating to UCP
http://www.access.hookom.net/UCP/Default.htm


Ruth said:
I want to do a calculation which calculates selling price from either Margin
% or Margin £ and if there is nothing in either field then I want to display
the text "no margin". I have tried the following formula:-

Sell Ex VAT: IIf([Margin %] Is Not Null,[Cost Price]+([Margin %]*[Cost
Price]),(IIf([Margin £] Is Not Null,[Cost Price]+[Margin £],"no margin")))

However, if there is nothing in either field, then it returns #Error.

Anyone got any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Building Expression in Query 2
NZ function 1
#Error when using IIF statement in a query 11
help me :( 2
CEILING 3
System Resource Exceeded/Query Too Complex 4
removing #Num! from txt box 7
Profit Margin 1

Top