Separating a joint name into separate components

Hi all,

I have just imported a long list of client names which includes single names and joint names into an Access database table.

Initially I would like a routine which actually separates  the table of  account names from the names into separate fields and assign the corresponding account number and addresses to it and create a new table with the new records. The logic that so far I can see is as follows:-

a] starting from the left the surname will be anything before the first comma.
b] the first name will be anything before the character before "&" or "&/Or" .
c] and so on until no more of the characters "&" or "&/Or" are in the field.

I am attaching an excel file which best depicts what I am trying to achieve.
Thanks, grateful for the assistance.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
create tableB like what you placed in the excel file

place this code in a regular module and run

Sub ParseField()
Dim rsA As DAO.Recordset, nameArr() As String, nameArr2() As String, j As Integer, rsB As DAO.Recordset
Set rsA = CurrentDb.OpenRecordset("tableA")
Set rsB = CurrentDb.OpenRecordset("tableB")

Do Until rsA.EOF
    nameArr = Split(rsA![Account Name], ",")
                nameArr2 = Split(nameArr(1), "&")
                For j = 0 To UBound(nameArr2)
                    With rsB
                        !Surname = nameArr(0)
                        ![Name] = Trim(Replace(nameArr2(j), "/or", ""))
                        !Add1 = rsA!Add1
                        !Add2 = rsA!Add2
                        !Add3 = rsA!Add3
                        !Account = rsA!Account
                   End With

End Sub

Open in new window

PipMicAuthor Commented:
Hi thanks for your reply,

However I am getting the following error

Run-time Error '9'
Subscript out of range
Rey Obrero (Capricorn1)Commented:
check the value of [Account Name] when you get the error.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

PipMicAuthor Commented:
The thing is that a error pops up but a number of records get done.

Very odd. In fact I'm checking a record that didnt "cross over" and its very like the one that did, except for the data itself??!
Rey Obrero (Capricorn1)Commented:
run this query
select *
from tableA
where instr([Account name], ",")=0

post the result
PipMicAuthor Commented:
It provides me with Account names that have no commas!!

Is that the issue?
Rey Obrero (Capricorn1)Commented:
<Is that the issue? >

yes. correct them and run the sub procedure again.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PipMicAuthor Commented:
Run-time errror  '3315'
Field tableB.Name cannot be zero length string

Rey Obrero (Capricorn1)Commented:
upload a copy of db with tableA and tableB
PipMicAuthor Commented:
Apologies Rey..... I have been unable to reply sooner
PipMicAuthor Commented:
Thanks anyway ..wil be assigning you the points
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.