Split a full name into FirstName, Lastname in Access VBA

Status
Not open for further replies.

adibakale

Board Regular
Joined
Apr 10, 2015
Messages
52
As part of a application I am developing, I added a command button on a form that will send the customers Name and Address to a word template letter that gets mailed to them.

This is the code I am using for this part of the process:

.ActiveDocument.Tables(2).Cell(1, 1).Select
.Selection.Text = Left(CStr(Forms!frm_Main!CHName), 4)



.Cell(1,1) in the first line is where the name goes in word, from
(Forms!frm_Main!CHName) in Access.

The format of the name in Access is

Smith, John A.

I would like it to show in Word in the format

John A Smith

I have been able to accomplish this using a specified amount of characters using Left and Right functions, but since the names will vary in length, specifying the amount of characters will not work.

Is there a way to get all text to the left of the comma and all text to the right?

Any help with this would be greatly appreciated
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Status
Not open for further replies.

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top