otac0n wrote:[color=blue]
> Thanks.
>
> But, is IIF part of SQL or VBA?[/color]
[color=blue]
>From the A97 help file for IIf:[/color]
You can also use the IIf function (immediate if) in a calculated
control on a Microsoft Access form or report. You can use the IIf
function to evaluate an expression and return either of two other
values, depending on whether the expression evaluates to True (-1) or
False (0).
[color=blue]
>From the Example:[/color]
You can enter the following expression in the ControlSource property of
a calculated control.
= IIf([OrderAmount] > 1000, "Large", "Small")
[color=blue]
>From Specifics:[/color]
In Visual Basic, the IIf function evaluates both truepart and
falsepart, even though it returns only one of them. In a Microsoft
Access form or report, however, the IIf function evaluates either
truepart or falsepart, whichever is appropriate. Therefore, you need
not be concerned about the undesirable side effects of evaluating both
arguments if you use the IIf function in a calculated control, query
expression, or macro.
In Visual Basic, the more full-featured If...Then...Else statement
offers greater versatility.
So the answer to your question seems to be that IIf can be useful in a
ControlSource or in a SQL query or in a macro, but is not recommended
for use in control flow when writing VBA code. E.g.,
If IsNull(Me!txtFirstName.Value) Then
strMergeName = Me!txtLastName.Value
Else
strMergeName = Me!txtFirstName.Value & " " & Me!txtLastName.Value
End If
is preferred over
strMergeName = IIf(IsNull(Me!txtFirstName.Value), Me!txtLastName.Value,
Me!txtFirstName & " " & Me!txtLastName.Value)
I hope this answers your question,
James A. Fortune
CDMAPoster@FortuneJames.com