I am very very new to Microsoft Access (databases/programming as well,
for that matter), and I need some help. I have a database that was
created by another party, and I'm trying to use some of it's
functionality in another database. But, I have no idea what a nested
iif statement is, and I have a couple that I need to know what it
does, so I can convert it appropriately to fit my new database. Here
are the 2 statements:
First:
File As: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[Company],
[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", "
& [First Name]))
Second:
Contact Name: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),
[Company],[First Name]),IIf(IsNull([First Name]),[Last Name],[First
Name] & " " & [Last Name]))
Could somebody please tell me how this works, and what it does? I
know that in an iif statement, it is:
IIF(expression,truepart,falsepart)... and that makes sense, but this
looks nothing like that, and I have no idea how to begin reading it.
Thanks again for your help!!!!!
A nested IIf() simply involves replacing the truepart or falsepart
(or both) with an IIf function .
Indenting your first example contains
IIf( #start of outside expression
IsNull([Last Name]),
IIf( # start of truepart of Outer IIf
IsNull([First Name]), # expression for inner IIF
[Company], # truepart for inner
[First Name] #falsepart for inner
), # end of first inner IIf
# start of Falsepart of Outer IIf
IIf(
IsNull([First Name]),
[Last Name],
[Last Name] & ", " & [First Name]
) # end of second inner IIf
) # end of first outer IIf
You already know all you need to know about nesting IIf
functions. Those are just using another
IIf(expression,truepart,falsepart) in the truepart and
falsepart of the outer IIf.
Might help if you broke it out as if it were a procedure:
If IsNull([Last Name]) Then
If IsNull([First Name]) Then
[Company]
Else
[First Name]
End If
Else 'do this when last name is NOT null
If IsNull([First Name]) Then
[Last Name]
Else
[First Name] & " " & [Last Name]
End If
End If
--
Marsh
If Lastname is null then
If firstname is null then
spit out company
else
spit out first name
endif
else
If firstname is null then
spit out last name
else
spit out last name and first name
endif
endif
>
> Second:
>
> Contact Name: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),
> [Company],[First Name]),IIf(IsNull([First Name]),[Last Name],[First
> Name] & " " & [Last Name]))
>
Pretty much the same thing as above. One is assigned to a column called
"File As" and the second as "Contact Name" in a query. The : separates
the column name from the value.
Thank you everybody for your help. I'm sorry I didn't reply
immediately... I had a baby boy and was deterred. I completely
understand now, thank you again!