What is the difference

What is the difference between IIF condition and IF condition ?
0
Utf
2/16/2008 6:22:00 AM
access.reports 4434 articles. 0 followers. Follow

3 Replies
743 Views

Similar Articles

[PageSpeed] 52

"Kutty" <Kutty@discussions.microsoft.com> wrote in message 
news:46A1B86F-2002-4548-916D-01E0B3F2C602@microsoft.com...
> What is the difference between IIF condition and IF condition ?

IIf() is a function that can be used directly in a query or control source.  If 
is used in VBA code only.

Unless you are thinking of the If() function from Excel in which case that does 
not apply to Access at all.

-- 
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com 


0
Rick
2/16/2008 12:53:54 PM
On Feb 16, 4:53 am, "Rick Brandt" <rickbran...@hotmail.com> wrote:
> "Kutty" <Ku...@discussions.microsoft.com> wrote in message
>
> news:46A1B86F-2002-4548-916D-01E0B3F2C602@microsoft.com...
>
> > What is the difference between IIF condition and IF condition ?
>
> IIf() is a function that can be used directly in a query or control source.  If
> is used in VBA code only.
>
> Unless you are thinking of the If() function from Excel in which case that does
> not apply to Access at all.
>
> --
> Rick Brandt, Microsoft Access MVP
> Email (as appropriate) to...
> RBrandt   at   Hunter   dot   com

the if statement return true or false and can be used in a query
though if then else can only be used in code.

table
cnt x y
try query

select cnt  x,y,if(x>=y) as test form table
cnt x y
1  3 2 true
2 2 3 false
3 3 3 true

IIF translates to  to if  then  A else B
it returns either A or B
this will return the biggest number between

select cnt  x,y,iif(x>=y,x,y)) as test form table

1 3 2 3
2 2 3 3
3 3 3 3

I use both use IIF a lot and is very powerful,

You can also nest them like iff(a>b),"Good),iif(c>d),"also
good","Bad")

the IF statement I use in code alot but the IF by itself in a query is
good but not a useful and more heavy duty logic problem.

the iif is an inline if then else statement and return Value A if true
and Value B if false
0
derek
2/17/2008 9:08:39 PM
note that
     iif(Expression, Truepart, Falsepart)
always evaluates both Truepart and Falsepart even though it only returns one 
of them. That means that an error can be generated by Falsepart even if 
Expression is True.

 This error is apparently supressed if you use the function in a query, but 
not if used in code.

        iif(i =0,0,10/i)

if i = 0, the above will generate a "Division by Zero" error if used in 
code, but not in a query.
-- 
HTH,
George


"derek@westcreekltd.com" <DBelsham@gmail.com> wrote in message 
news:e06913ab-dd2b-4958-b5f8-321ba9a02f11@s19g2000prg.googlegroups.com...
> On Feb 16, 4:53 am, "Rick Brandt" <rickbran...@hotmail.com> wrote:
>> "Kutty" <Ku...@discussions.microsoft.com> wrote in message
>>
>> news:46A1B86F-2002-4548-916D-01E0B3F2C602@microsoft.com...
>>
>> > What is the difference between IIF condition and IF condition ?
>>
>> IIf() is a function that can be used directly in a query or control 
>> source.  If
>> is used in VBA code only.
>>
>> Unless you are thinking of the If() function from Excel in which case 
>> that does
>> not apply to Access at all.
>>
>> --
>> Rick Brandt, Microsoft Access MVP
>> Email (as appropriate) to...
>> RBrandt   at   Hunter   dot   com
>
> the if statement return true or false and can be used in a query
> though if then else can only be used in code.
>
> table
> cnt x y
> try query
>
> select cnt  x,y,if(x>=y) as test form table
> cnt x y
> 1  3 2 true
> 2 2 3 false
> 3 3 3 true
>
> IIF translates to  to if  then  A else B
> it returns either A or B
> this will return the biggest number between
>
> select cnt  x,y,iif(x>=y,x,y)) as test form table
>
> 1 3 2 3
> 2 2 3 3
> 3 3 3 3
>
> I use both use IIF a lot and is very powerful,
>
> You can also nest them like iff(a>b),"Good),iif(c>d),"also
> good","Bad")
>
> the IF statement I use in code alot but the IF by itself in a query is
> good but not a useful and more heavy duty logic problem.
>
> the iif is an inline if then else statement and return Value A if true
> and Value B if false 


0
George
2/18/2008 8:17:04 PM
Reply:

Similar Artilces: