IIf statement help

N

Nancy

I want to concatenate a person's name so that the result will not include an
extra space if the person does not have a middle name or initial. This is
what I have written but I know it is not correct. Can you please correct it
for me?

Name: IIF([strPMName] is null [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])
 
J

Jeff L

IIF(IsNull([strPMName]), [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])

Another way you could do it:
[strPFName]&" " & iif(IsNull(strPMName), strPLastName, strPMName & " "
& strPLastName)
 
J

Jeff L

IIF(IsNull([strPMName]), [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])

Another way you could do it:
[strPFName]&" " & iif(IsNull(strPMName), strPLastName, strPMName & " "
& strPLastName)

Hope that helps!
 
F

fredg

I want to concatenate a person's name so that the result will not include an
extra space if the person does not have a middle name or initial. This is
what I have written but I know it is not correct. Can you please correct it
for me?

Name: IIF([strPMName] is null [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])

You can concatenate the middle name and it's space using + instead of
&. If the middle name is null the space will not appear.

CombinedNames: [FirstName] & (" "+[MiddleName]) & " " & [Last Name]
 
N

Nancy

Thanks Jeff -- except that neither of those work exactly right. I copied and
pasted so I'm pretty sure I did not err in the statement.

In your first suggestion, it picked up the first and last names but when the
middle one was entered, the result dropped back to first name only.

In your 2nd suggestion, the result dropped back to first name and middle
name and dropped the last name.

Please try again. I am most grateful for your assistance!
--
nhb -- nc


Jeff L said:
IIF(IsNull([strPMName]), [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])

Another way you could do it:
[strPFName]&" " & iif(IsNull(strPMName), strPLastName, strPMName & " "
& strPLastName)

Hope that helps!


I want to concatenate a person's name so that the result will not include an
extra space if the person does not have a middle name or initial. This is
what I have written but I know it is not correct. Can you please correct it
for me?

Name: IIF([strPMName] is null [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])
 
N

Nancy

OK -- thanks Fred. I'll try that one too!

Jeff -- I went back and typed it in myself instead of copying and pasting
and it worked! I can't see any difference but it works and that's what's
important.

Many thanks to you both!!
--
nhb -- nc


fredg said:
I want to concatenate a person's name so that the result will not include an
extra space if the person does not have a middle name or initial. This is
what I have written but I know it is not correct. Can you please correct it
for me?

Name: IIF([strPMName] is null [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])

You can concatenate the middle name and it's space using + instead of
&. If the middle name is null the space will not appear.

CombinedNames: [FirstName] & (" "+[MiddleName]) & " " & [Last Name]
 
J

Jeff L

I have tested both of them using the same field names you use. The
first one worked fine, not sure why you are having trouble. The second
one I used LastName instead of LName. When I changed it, that to
worked the way it was supposed to.


Thanks Jeff -- except that neither of those work exactly right. I copied and
pasted so I'm pretty sure I did not err in the statement.

In your first suggestion, it picked up the first and last names but when the
middle one was entered, the result dropped back to first name only.

In your 2nd suggestion, the result dropped back to first name and middle
name and dropped the last name.

Please try again. I am most grateful for your assistance!
--
nhb -- nc


Jeff L said:
IIF(IsNull([strPMName]), [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])

Another way you could do it:
[strPFName]&" " & iif(IsNull(strPMName), strPLastName, strPMName & " "
& strPLastName)

Hope that helps!


I want to concatenate a person's name so that the result will not include an
extra space if the person does not have a middle name or initial. This is
what I have written but I know it is not correct. Can you please correct it
for me?

Name: IIF([strPMName] is null [strPFName]&" "&[strPLName], [strPFName]&"
"&[strPMName]&" "&[strPLName])
 
Top