Combine name fields

G

Guest

Hello,

I'm trying to have a name field in one table look up a first and last name
field in another table and combine them into one field. Trouble is, I need to
insert a space between the first and last names to separate them. How can I
do that?

Thank you.
 
G

Guest

Hi Niniel

In a query
Name:[1stNameField]&" "&[2ndNameField]

On a form (field's control source)
=[1stNameField]&" "&[2ndNameField]

The use of & will add anything aterwards to anything befor so by adding
double comas you are adding a text string (anthing you put between the " ")
and in this case you are place a space.

Hope this helps
 
G

Guest

Thanks a lot, it works!

I could have sworn I tried this myself though and it didn't work... maybe
it's because I had [field] & " " & [field] vs. [field]&" "&[field].

Wayne-I-M said:
Hi Niniel

In a query
Name:[1stNameField]&" "&[2ndNameField]

On a form (field's control source)
=[1stNameField]&" "&[2ndNameField]

The use of & will add anything aterwards to anything befor so by adding
double comas you are adding a text string (anthing you put between the " ")
and in this case you are place a space.

Hope this helps


--
Wayne
Manchester, England.
Not an expert
Enjoy whatever it is you do


Niniel said:
Hello,

I'm trying to have a name field in one table look up a first and last name
field in another table and combine them into one field. Trouble is, I need to
insert a space between the first and last names to separate them. How can I
do that?

Thank you.
 
G

Guest

Hi Niniel

I looked at the oringinal [field] & " " & [field] which was almost there.
You should remember that a space really is a space "it isn't nothing". You
have a space between & and the ".

Good luck with your new data base.

--
Wayne
Manchester, England.
Not an expert
Enjoy whatever it is you do


Niniel said:
Thanks a lot, it works!

I could have sworn I tried this myself though and it didn't work... maybe
it's because I had [field] & " " & [field] vs. [field]&" "&[field].

Wayne-I-M said:
Hi Niniel

In a query
Name:[1stNameField]&" "&[2ndNameField]

On a form (field's control source)
=[1stNameField]&" "&[2ndNameField]

The use of & will add anything aterwards to anything befor so by adding
double comas you are adding a text string (anthing you put between the " ")
and in this case you are place a space.

Hope this helps


--
Wayne
Manchester, England.
Not an expert
Enjoy whatever it is you do


Niniel said:
Hello,

I'm trying to have a name field in one table look up a first and last name
field in another table and combine them into one field. Trouble is, I need to
insert a space between the first and last names to separate them. How can I
do that?

Thank you.
 
J

John Vinson

Hello,

I'm trying to have a name field in one table look up a first and last name
field in another table and combine them into one field. Trouble is, I need to
insert a space between the first and last names to separate them. How can I
do that?

Thank you.

If you're trying to store the concatenated name in a second table...
DON'T. It's redundant, and a Very Bad Idea.

You can *display* the name whenever it's needed, while storing the
unique ID of that person from the table containing the names: a
calculated field such as

FullName: [FirstName] & " " & [LastName]

will build a string with a blank between the names. Again, this should
almost surely *not* be stored in any table, since it can be
regenerated whenever it's needed.

John W. Vinson[MVP]
 
J

John Vinson

Hi Niniel

I looked at the oringinal [field] & " " & [field] which was almost there.
You should remember that a space really is a space "it isn't nothing". You
have a space between & and the ".

I beg to differ...

The spaces outside the quotes are there just for readability, and they
do not affect the result.

[Field] & " " & [Field]

is correct and will return "John Doe" if that's what's in the two
fields.

Niniel might have had

[Field] & "" & [Field]

(with or without spaces around the ampersands, it wouldn't matter)
which would concatenate an empty string, giving "JohnDoe" as a result.

John W. Vinson[MVP]
 
G

Guest

Hi John

I just tested the answer you gave. I was always taught that any spaces
should be treated as text and included within the quotes.

Your answer was perfectly correct.

I have learnt something new today. Thanks for that. I'll get the hang of
this stuff one day :)
 
J

John Vinson

I just tested the answer you gave. I was always taught that any spaces
should be treated as text and included within the quotes.

sure... any spaces which you want to be *treated* as text need to be
part of the text. Spaces outside the quotes are just for code
readability; in the same way that

4 + 65

and

4+65

are equivalent, so are

"A" & "B"

and

"A"&"B"


John W. Vinson[MVP]
 

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