using iff statement in a form

lubbs65

Board Regular
Joined
Jun 1, 2011
Messages
80
i am trying to use an iff statement in a form.
pretty much the statement would be in a savings textbox
i can type = [revenue]-[cost] and i get a result.

however, it has to be ok for [cost] to be blank. therefore, i've tried:

iif([cost] is NULL, [revenue], [revenue]-[cost])

this did not work. i wasn't sure if it was my syntax in "[cost] is NULL" so i tried:

iif([cost] =100, [revenue], [revenue]-[cost])

this still just gave me #name in the text box. What am I doing wrong?
I've been under the impression that I can simply just type that into the textbox in design view but clearly it has not been working.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Why not add that expression to the query the form is based on?

Savings:[Revenue] - Nz([cost], 0)

You could then use that as the control source for your savings textbox.

You could just enter it, with a = in from, in the Control Source property of the textbox.
 
Upvote 0
If you don't add it to the query, then you have to use the IIF properly for the control source. It should start with an = sign and then it is best if the controls involved in the calculation are not named the same as the fields that you have. Also you don't use Is Null in this case you would use:

=IIf (IsNull([cost]), Nz([revenue], 0), Nz([revenue],0) - Nz([cost], 0))

but that can be broken down to simply:

=Nz([revenue],0) - Nz([cost],0)

As it will provide the right answer regardless. So no IIF statement is actually needed.
 
Upvote 0
Bob

I was able to use the expression I posted in the control source without Iif.
 
Upvote 0
Bob

I was able to use the expression I posted in the control source without Iif.
Without the equals sign? That is what I had asked about, not the IIF (I had stated "To use the IIF PROPERLY..."). I know you can do it without the IIF as I put in my last post. :stickouttounge:
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top