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.
if i = 0, the above will generate a "Division by Zero" error if used in
code, but not in a query.
"email@example.com" <DBelsham@gmail.com> wrote in message
> On Feb 16, 4:53 am, "Rick Brandt" <rickbran...@hotmail.com> wrote:
>> "Kutty" <Ku...@discussions.microsoft.com> wrote in message
>> > 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.
> 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
> 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