IIF function

A

Ashley

Hi,
I have below function in the control source. It returned #name?
Basically, I would like "if totalminutes is zero, then this field is
zero,else 60/totalminutes
IIf([TR_PRICING].[Form]![TOTALMINUTES] Is
Null,0,(60/[TR_PRICING].[Form]![TOTALMINUTES]))

Where should I put this IIF function?
Thanks
 
G

golfinray

IIF statements are laid out like this:

IIF([yourtable!yourfield]is null,[what to do if true],[what to do if false])
 
A

Ashley

This is a control field. It is unbound to a table. What should the statement
looks like?

golfinray said:
IIF statements are laid out like this:

IIF([yourtable!yourfield]is null,[what to do if true],[what to do if false])
--
Milton Purdy
ACCESS
State of Arkansas


Ashley said:
Hi,
I have below function in the control source. It returned #name?
Basically, I would like "if totalminutes is zero, then this field is
zero,else 60/totalminutes
IIf([TR_PRICING].[Form]![TOTALMINUTES] Is
Null,0,(60/[TR_PRICING].[Form]![TOTALMINUTES]))

Where should I put this IIF function?
Thanks
 
K

KARL DEWEY

Where are you wanting to use it as it makes no sense.
It is testing for a value and isplaying zero if no value but dividing 60 by
the value if it exist.
If you divides minutes by 60 you get hours but what do you get dividing 60
by a number of minutes?

BTW golfinray stated how it should look.

--
Build a little, test a little.


Ashley said:
This is a control field. It is unbound to a table. What should the statement
looks like?

golfinray said:
IIF statements are laid out like this:

IIF([yourtable!yourfield]is null,[what to do if true],[what to do if false])
--
Milton Purdy
ACCESS
State of Arkansas


Ashley said:
Hi,
I have below function in the control source. It returned #name?
Basically, I would like "if totalminutes is zero, then this field is
zero,else 60/totalminutes
IIf([TR_PRICING].[Form]![TOTALMINUTES] Is
Null,0,(60/[TR_PRICING].[Form]![TOTALMINUTES]))

Where should I put this IIF function?
Thanks
 
B

Bob Quintal

Hi,
I have below function in the control source. It returned #name?
Basically, I would like "if totalminutes is zero, then this field is
zero,else 60/totalminutes
IIf([TR_PRICING].[Form]![TOTALMINUTES] Is
Null,0,(60/[TR_PRICING].[Form]![TOTALMINUTES]))

Where should I put this IIF function?
Thanks

I think you have the naming of your control backwards.
Is TR_Pricing the name of the form, and TOTALMINUTES the name of the
control on that form?

If yes then
Try Forms![TR_PRICING]![TOTALMINUTES]
 
L

Linq Adams via AccessMonster.com

Everything else aside, in Access, the correct syntax is

IIf(IsNull([TR_PRICING].[Form]![TOTALMINUTES])
 
A

Ashley

If the totalminutes is not zero, the calculated control (60/[totalminutes])
is fine. But when totalminutes is zero, the field display #div/0!. But I
would like it to display zero.

KARL DEWEY said:
Where are you wanting to use it as it makes no sense.
It is testing for a value and isplaying zero if no value but dividing 60 by
the value if it exist.
If you divides minutes by 60 you get hours but what do you get dividing 60
by a number of minutes?

BTW golfinray stated how it should look.

--
Build a little, test a little.


Ashley said:
This is a control field. It is unbound to a table. What should the statement
looks like?

golfinray said:
IIF statements are laid out like this:

IIF([yourtable!yourfield]is null,[what to do if true],[what to do if false])
--
Milton Purdy
ACCESS
State of Arkansas


:

Hi,
I have below function in the control source. It returned #name?
Basically, I would like "if totalminutes is zero, then this field is
zero,else 60/totalminutes
IIf([TR_PRICING].[Form]![TOTALMINUTES] Is
Null,0,(60/[TR_PRICING].[Form]![TOTALMINUTES]))

Where should I put this IIF function?
Thanks
 
K

KARL DEWEY

What is the results of 60/[totalminutes]? Days, hours, minutes, seconds,
moments, or what kind of unit?

--
Build a little, test a little.


Ashley said:
If the totalminutes is not zero, the calculated control (60/[totalminutes])
is fine. But when totalminutes is zero, the field display #div/0!. But I
would like it to display zero.

KARL DEWEY said:
Where are you wanting to use it as it makes no sense.
It is testing for a value and isplaying zero if no value but dividing 60 by
the value if it exist.
If you divides minutes by 60 you get hours but what do you get dividing 60
by a number of minutes?

BTW golfinray stated how it should look.

--
Build a little, test a little.


Ashley said:
This is a control field. It is unbound to a table. What should the statement
looks like?

:

IIF statements are laid out like this:

IIF([yourtable!yourfield]is null,[what to do if true],[what to do if false])
--
Milton Purdy
ACCESS
State of Arkansas


:

Hi,
I have below function in the control source. It returned #name?
Basically, I would like "if totalminutes is zero, then this field is
zero,else 60/totalminutes
IIf([TR_PRICING].[Form]![TOTALMINUTES] Is
Null,0,(60/[TR_PRICING].[Form]![TOTALMINUTES]))

Where should I put this IIF function?
Thanks
 
P

Petr Danes

Hi Ashley,

you're mixing up two things, it seems to me: nulls and zero values, which
are not at all the same thing. Look at your statement:

IIf(
[TR_PRICING].[Form]![TOTALMINUTES] Is Null,
0,
(60/[TR_PRICING].[Form]![TOTALMINUTES])
)

You're testing to see whether it is null, not zero, so that when it is zero,
the test returns false and you go to the second condition, i.e., dividing 60
by TOTALMINUTES. Since TOTALMINUTES is zero, you naturally get a
divide-by-zero error.

If you really want things as you say, change the test clause in your IIF
statement to read:
TR_PRICING].[Form]![TOTALMINUTES] = 0

This, however, may bomb if you do, in fact, have nulls in your data. If so,
you will probably need something like this:
nz(TR_PRICING].[Form]![TOTALMINUTES]) = 0
or maybe even
Val(nz(TR_PRICING].[Form]![TOTALMINUTES])) = 0
depending on what data types you have in your source.

Pete



Ashley said:
If the totalminutes is not zero, the calculated control
(60/[totalminutes])
is fine. But when totalminutes is zero, the field display #div/0!. But I
would like it to display zero.

KARL DEWEY said:
Where are you wanting to use it as it makes no sense.
It is testing for a value and isplaying zero if no value but dividing 60
by
the value if it exist.
If you divides minutes by 60 you get hours but what do you get dividing
60
by a number of minutes?

BTW golfinray stated how it should look.

--
Build a little, test a little.


Ashley said:
This is a control field. It is unbound to a table. What should the
statement
looks like?

:

IIF statements are laid out like this:

IIF([yourtable!yourfield]is null,[what to do if true],[what to do if
false])
--
Milton Purdy
ACCESS
State of Arkansas


:

Hi,
I have below function in the control source. It returned #name?
Basically, I would like "if totalminutes is zero, then this field
is
zero,else 60/totalminutes
IIf([TR_PRICING].[Form]![TOTALMINUTES] Is
Null,0,(60/[TR_PRICING].[Form]![TOTALMINUTES]))

Where should I put this IIF function?
Thanks
 
B

Bob Quintal

Everything else aside, in Access, the correct syntax is

IIf(IsNull([TR_PRICING].[Form]![TOTALMINUTES])
Only sometimes!

That syntax assumes that the code is in a form which contains a subform
control named [TR_PRICING], which in turn contains a textbox named
[TOTALMINUTES].


The syntax I posted IS valid for the condition I asked about. The OP
was not clear.

see http://www.mvps.org/access/forms/frm0031.htm
 

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

Calculating Time 5
Using Min Function within DLookup Function 0
Text box Formula Error Message 2
Time Function 3
Need some PWA help 0
Elapsed Time Assistance 3
Time calculations 1
Problem w/Date time function 2

Top