stName: [FirstName] & (" " + NZ("(" + [PreferredName] + ")", [SecondName])) &
" " & [LastName]
Which " " are you talking about?
It's probably the concatenation inside the brackets. When you concatenate
strings, you can either use the & or the + to do the concatenation. If you
use the &, Access will give you what is on the left, tacked onto what is on
the right, regardless of whether the left or right is NULL. If you use the
+, then access will look at both sides of the + and if either value is NULL,
it will return a NULL. So:
"A" & "B" = "AB"
"A" & NULL = "A"
"A" + "B" = "AB"
"A" + NULL = NULL
So, in the modified code I gave you above the stuff inside the NZ( )
function will get evaluated as:
NZ("(" + [PreferredName] + ")", [SecondName])
IF [PreferredName] is NULL then using the + sign to concatenate the "(" and
")" to it will still return a NULL, so [SecondName] would get returned. If
[PreferredName] is not Null, then this new code would return (Munjo) as in
your example.
You can use this technique to your advantage in a lot of situations, but the
one I find most useful is with names, similar to what you are doing.
--
HTH
Dale
email address is invalid
Please reply to newsgroup only.
Sue Compelling said:
This was brilliant Dale - there's no way I would have been able to have
distilled my logic like that.
Two things however:
Using your abbreviated code my Preferred Name doesn't have the brackets
around it eg: Malo (Munji) Fandango - is there a way to do that using your
statement? (It does work with the correction you supplied me)
Do you have a minute to explain what the " " in your statement does?
Kind Regards
Sue
--
Sue Compelling
:
Sue,
I think your problem is in the second IIF clause.
Change: IIF([PreferredName] is not NULL),
To: IIF([PreferredName] is not NULL,
However, when you look at your logic, you can simplify this considerably.
Basically, your logic says, include the First and Last name in all cases, and
include the [PreferredName] if it is not null, otherwise include the
[SecondName] if it is not null. So you should be able to use:
stName: [FirstName] & (" " + NZ([PreferredName], [SecondName])) & " " &
[LastName]
By concatenating the " " and the NZ( ) function using a + sign, you will get
one of the following conditions:
IF both [PreferredName] and [SecondName] are NULL, you will get
[FirstName] & " " & [LastName]
IF [PreferredName] is NULL and [SecondName] is not, you will get
[FirstName] & " " & [SecondName] & " " & [LastName]
IF [PreferredName] is not NULL and [SecondName] is NULL, you will get
[FirstName] & " " & [PreferredName] & " " & [LastName]
--
HTH
Dale
email address is invalid
Please reply to newsgroup only.
:
Hi ALL
I get an error message on this expressiin stating I have too many arguments
and have been unable to correct it.
TIA
StName: IIf(IsNull([SecondName]),IIf([PreferredName]is not null),[FirstName]
& " (" & [PreferredName] & ") " &
[LastName],IIf(IsNull([SecondName]),IIf(IsNull([PreferredName]),[FirstName] &
" " & [LastName],[FirstName] & " " & [SecondName] & " " & [LastName]))))