iif Expression Error

Z

zyus

Something is not right with my below iif expression where i get this error
"You Can Use Is Operator Only In An Expression With Null Or Not Null"

NEWJArrAmt: IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Help please

Thanks
 
K

kc-mass

Try it this way:

NEWJArrAmt: IIf(IsNull([TBL-SKS].[arramt]) &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf(IsNull([TBL-SKS].[arramt]) &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Regards

Kevin
 
D

Duane Hookom

I don't even want to begin sorting out nested IIf()s. IMO, this type of
calculation belongs in a public function where you can add comments and
re-use it over and over as needed. Save the module as "modBusinessCalcs".

BTW: If you really can stand all the IIf()s, consider replacing all the &s
with ANDs.

--
Duane Hookom
MS Access MVP


kc-mass said:
Try it this way:

NEWJArrAmt: IIf(IsNull([TBL-SKS].[arramt]) &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf(IsNull([TBL-SKS].[arramt]) &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Regards

Kevin



zyus said:
Something is not right with my below iif expression where i get this
error
"You Can Use Is Operator Only In An Expression With Null Or Not Null"

NEWJArrAmt: IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Help please

Thanks
 
J

John W. Vinson

Something is not right with my below iif expression where i get this error
"You Can Use Is Operator Only In An Expression With Null Or Not Null"

NEWJArrAmt: IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Help please

Thanks

I agree with Duane - nested IIF gets complex, hard to read and inefficient -
but the problem that's causing this error message is that you're using the
concatenation operator & rather than the SQL conjunction AND. Replace your
ampersands by the word AND - see if that doesn't make it better.

You also need a FALSE branch for your last IIF. Could you describe in words,
or a little table, what result you want for the different combinations of the
two arramt fields?
 
Z

zyus

Change "&" with "And" and it runs successfully

Thanks

kc-mass said:
Try it this way:

NEWJArrAmt: IIf(IsNull([TBL-SKS].[arramt]) &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf(IsNull([TBL-SKS].[arramt]) &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Regards

Kevin



zyus said:
Something is not right with my below iif expression where i get this error
"You Can Use Is Operator Only In An Expression With Null Or Not Null"

NEWJArrAmt: IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Help please

Thanks


.
 
G

Guest

zyus said:
Something is not right with my below iif expression where i get this error
"You Can Use Is Operator Only In An Expression With Null Or Not Null"

NEWJArrAmt: IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]=0,[JColl],IIf([TBL-SKS].[arramt]=0 &
[TBL-previousmonth].[arramt]=0,[Jcoll],IIf([TBL-SKS].[arramt] Is Null &
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],IIf([TBL-SKS].[arramt]=0
&
[TBL-previousmonth].[arramt]>0,[TBL-previousmonth].[arramt],[TBL-SKS].[arramt]))))

Help please

Thanks
 

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

Query Null 1
Calculation In Query 1
IiF in Query 2
Calculation in Update query drops decimal places 2
query too slow 1
"data type mismatch" 6
Run-time error '3075' 10
syntax error 3075 11

Top