Eliminate "," if no first name in cancatenated expression

S

Sue

I have an expression as follows:

=lastname & ", " & firstname

but some of the expressions don't have a first name.

Can I chunk the comma in such a situation?


THANK YOU!!!
 
A

Allen Browne

Try:
= [lastname] & ", " + [firstname]

This relies on a subtle difference between the 2 concatenation operators in
Access:
"A" & Null => "A"
"A" + Null => Null
 
S

Sue

Thank you - That fixed it 100% (although I'm not clear on the subtleties
here...).
You've rescued me from the morass yet again - I appreciate your help, Allen!
--
Thanks for your time!


Allen Browne said:
Try:
= [lastname] & ", " + [firstname]

This relies on a subtle difference between the 2 concatenation operators in
Access:
"A" & Null => "A"
"A" + Null => Null

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Sue said:
I have an expression as follows:

=lastname & ", " & firstname

but some of the expressions don't have a first name.

Can I chunk the comma in such a situation?


THANK YOU!!!
 
D

David W. Fenton

Try:
= [lastname] & ", " + [firstname]

This relies on a subtle difference between the 2 concatenation
operators in Access:
"A" & Null => "A"
"A" + Null => Null

But you don't want the ", " if there is no lastname. This works in
all cases:

Mid(("12" + LastName) & (", " + FirstName),3)
 
S

Sue

That looked like a cool trick, but it didn't work when I pasted your
expression into my report. Could an operand be missing?
--
Thanks for your time!


David W. Fenton said:
Try:
= [lastname] & ", " + [firstname]

This relies on a subtle difference between the 2 concatenation
operators in Access:
"A" & Null => "A"
"A" + Null => Null

But you don't want the ", " if there is no lastname. This works in
all cases:

Mid(("12" + LastName) & (", " + FirstName),3)
 
D

David W. Fenton

That looked like a cool trick, but it didn't work when I pasted
your expression into my report. Could an operand be missing?

I just pasted it into a query where the fields had that name, and it
worked perfectly. Are your fields named "LastName" and "FirstName"?
If not, you need to change it accordingly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top