problems using IIf

R

Rob

In a database, I have a table with tree fields: FirstName, MiddleName
and LastName

Using a Query, I would like to get either:

Firstname & " " & MiddleName & " " & LastName (if MiddelName is not empty)

or

FirstName & " " & LastName (if MiddelName is empty)

I tried things like:

Name: IIf(IsNull[MiddleName];(FirstName & " " & LastName);(Firstname &
" " & MiddleName & " " & LastName))

but keep getting "invalid syntax" errors.

Help anyone? Much obliged.

Rob
 
J

John Spencer

Your syntax error comes from the missing parentheses () in the criteria section
of the IIF expression.

Name: IIf(IsNull([MiddleName]);FirstName & " " & LastName;Firstname &
" " & MiddleName & " " & LastName)

You could also use the following in a query.

Name: IIf([MiddleName] is Null;FirstName & " " & LastName;Firstname &
" " & MiddleName & " " & LastName)
 
T

Tom Lake

Rob said:
In a database, I have a table with tree fields: FirstName, MiddleName and
LastName
I tried things like:

Name: IIf(IsNull[MiddleName];(FirstName & " " & LastName);(Firstname & "
" & MiddleName & " " & LastName))

but keep getting "invalid syntax" errors.

Have you tried using commas instead of semi-colons to separate the
arguments?

Tom Lake
 
R

RoyVidar

Tom Lake said:
Rob said:
In a database, I have a table with tree fields: FirstName,
MiddleName and LastName
I tried things like:

Name: IIf(IsNull[MiddleName];(FirstName & " " &
LastName);(Firstname & " " & MiddleName & " " & LastName))

but keep getting "invalid syntax" errors.

Have you tried using commas instead of semi-colons to separate the
arguments?

Tom Lake

Some of us lives places where comma is used as decimalseparator. Then
comma can't be used as arguementseparator in queries and expressions
in the UI (same goes also for Excel functions), and we use semicolon
;-)
 
Top