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.
Splitting-Names.xlsx
PipMicAsked:
Who is Participating?
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
                        .AddNew
                        !Surname = nameArr(0)
                        ![Name] = Trim(Replace(nameArr2(j), "/or", ""))
                        !Add1 = rsA!Add1
                        !Add2 = rsA!Add2
                        !Add3 = rsA!Add3
                        !Account = rsA!Account
                        .Update
                   End With
                Next
rsA.MoveNext
Loop

rsA.Close
rsB.Close
End Sub

Open in new window

.
1
PipMicAuthor Commented:
Hi thanks for your reply,

However I am getting the following error

Run-time Error '9'
Subscript out of range
0
Rey Obrero (Capricorn1)Commented:
check the value of [Account Name] when you get the error.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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??!
0
Rey Obrero (Capricorn1)Commented:
run this query
select *
from tableA
where instr([Account name], ",")=0

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

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

yes. correct them and run the sub procedure again.
0

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

?
0
Rey Obrero (Capricorn1)Commented:
upload a copy of db with tableA and tableB
0
PipMicAuthor Commented:
Apologies Rey..... I have been unable to reply sooner
0
PipMicAuthor Commented:
Thanks anyway ..wil be assigning you the points
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.