Hi Chris
You don't need to go to the trouble of exporting and importing. There are
plenty of string manipulation functions in VBA which will do the job for
you.
Extracting the last name is easy because it's everything up to the comma.
Dim sFullName as string
Dim sLast as string
Dim sRest as String
Dim i as integer
' find the position of the comma
i = InStr( sFullName, "," )
sLast = Left( sFullName, i-1 )
sRest = Mid( sFullName, i+1 )
If the format of the rest of the string is completely consistent then it can
be split up in a similar way by finding the spaces. However, there may be
problems. Consider the following names:
1. Smith,Mary Jane Q
2. Smith,John Jnr
3. Smith,John Q
(1) has a double (but unhyphenated) first name, a middle initial, and no
suffix
(2) has a suffix but no middle initial
(3) has a middle initial but no suffix
No code will be clever enough to parse these correctly, as certain human
judgements need to be made.
What you could do is write a query to find the "problem" names, and edit
them to make them consistent. The following match criterion will find most
of them:
Not Like "*,* [A-Z] *"
You can then manually make temporary changes to them as required - for
example, change any spaces in first names to "@" and add a bogus middle
initial such as "%" to those names that don't have one.
Then you can split out the other three fields based on a space delimiter and
do a global replace later to remove your temporary characters.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Chris said:
I have a name field that contains the following format:
Last,First M Suffix
How can I split each portion out into its separate column (4 Columns):
Last
First
Middle Initial (if one is there)
Suffix (this can be anywhere from 2 to 10 characters)
Thank you for any advice and help that you can give me.