I want to Concatenate First Name and Last Name fields into Full Name Field (1 Viewer)

Zubair Mughal

New member
Local time
Today, 22:00
Joined
Sep 10, 2020
Messages
3
I have 3 fields in my Staff database.

First Name;

Last Name;

Full Name.

I want to Concatenate First Name and Last Name fields to STORE/SAVE in Full Name fields at frmStaff on tblStaff.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:00
Joined
May 7, 2009
Messages
19,169
Add code to the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as integer)
[Full Name] = [First Name] & (" " + [Last Name])
End sub

[Full Name] must be added to the form.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:00
Joined
Oct 29, 2018
Messages
21,358
Hi. Welcome to AWF!

Also, you could consider using a Calculated Column.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:00
Joined
Apr 27, 2015
Messages
6,283
As I posted on Bytes:

Hello there!

Easy to do, but I would suggest NEVER storing concatenated data. It is a better practice to do this for Forms, Reports, and Queries - but not in a table. What if the name changes, or if you make a mistake and have to change it?

Anyway, to answer your question:

[First Name] & " " & [Last Name]

- or -

[Last Name] & ", " & [First Name]

Again, I strongly urge you to not do this at the table level...

I would add that Arnel's code is much cleaner if you choose to store this data - which you shouldn't - but since I don't beat dead horses...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:00
Joined
Oct 29, 2018
Messages
21,358
As I posted on Bytes:



I would add that Arnel's code is much cleaner if you choose to store this data - which you shouldn't - but since I don't beat dead horses...
Just as FYI... Calculated Columns are available in Access and in SQL Server (and SharePoint). When you update any of the fields involved in the calculation, the calculated column is automatically updated also (no out of sync situation and you don't have to remember to do anything). :)
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:00
Joined
Apr 27, 2015
Messages
6,283
Just as FYI... Calculated Columns are available in Access and in SQL Server (and SharePoint). When you update any of the fields involved in the calculation, the calculated column is automatically updated also (no out of sync situation and you don't have to remember to do anything). :)
I see...good to know! I just have always stayed away from them because those much smarter than me (not hard to make that list!) have always said "that way lies madness". I but them in the same category as Multi-Valued Fields.

So...

In your opinion and experience, are calculated fields victim of bad-press and unfounded allegations?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:00
Joined
Oct 29, 2018
Messages
21,358
I see...good to know! I just have always stayed away from them because those much smarter than me (not hard to make that list!) have always said "that way lies madness". I but them in the same category as Multi-Valued Fields.

So...

In your opinion and experience, are calculated fields victim of bad-press and unfounded allegations?
Hi. Obviously, no system is perfect. But, if something is available in Access, but not available in SQL Server, e.g. Attachment Fields, MVFs, then I would avoid them too. However, since Calculated Columns are available to both, I don't see any harm in using them in Access or SQL Server. Still, it's just an option. No one is saying you "have to" use them.
 

vhung

Member
Local time
Today, 10:00
Joined
Jul 8, 2020
Messages
235
I have 3 fields in my Staff database.
First Name;
Last Name;
Full Name.
I want to Concatenate First Name and Last Name fields to STORE/SAVE in Full Name fields at frmStaff on tblStaff.
3 fields were given
> no worries
> would be: [Full Name]=[Last Name] & ", "& [First Name]
> on [Last Name] and [First Name] update insert code above
 

Zubair Mughal

New member
Local time
Today, 22:00
Joined
Sep 10, 2020
Messages
3
Add code to the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as integer)
[Full Name] = [First Name] & (" " + [Last Name])
End sub

[Full Name] must be added to the form.

That’s the perfect as I required. Thanks a lot.
 

Users who are viewing this thread

Top Bottom