Hi Ray,
Any such algorithm that you might come up with would need to allow for last
names that include a space as well. Honestly, you will be a lot better off to
permanantly split the field in question into two or more fields. This way,
you can apply appropriate indexing, so as to avoid a full table scan. This is
especially important in the table in question has lots of records, and a
network separates you from your data.
One of my favorite utilities for splitting names in Access is called
"Splitter for Microsoft Access". If you don't mind popping $39 for a copy,
you will have a very good utility that can untangle the messiest name data:
http://www.infoplan.com.au/splitter/
A very easy method to use involves exporting the table to Excel. From within
Excel, use Data > Text to Columns... Then re-import your table back into
Access.
You can also create the new fields in the table and then use an update query
to populate the new fields. The update query would look like this:
Field: LastName
Table: Your tablename
Update To: SplitName([FullName],0)
Field: FirstName
Table: Your tablename
Update To: SplitName([FullName],1)
Field: MiddleInitial
Table: Your tablename
Update To: SplitName([FullName],2)
Create a new standard module. Then copy and paste the following function
into it. This will create a zero-based array named strResult. The On Error
Resume Next statement will prevent the function from choking to a halt if
there is no middle name for a given record.
Public Function SplitName(FullName As String, _
intElement As Integer) As String
On Error Resume Next
Dim strResult() As String
strResult = Split([FullName], Chr(32))
SplitName = strResult(intElement)
End Function
======================
Update: 5-Nov-2006 for Name data in the format: LastName, FirstName MI
(i.e. comma in-between Lastname and Firstname, but a space in-between
Firstname and MI. In this case, the user did not want to retain the middle
initial).
http://groups.google.com/group/micr..._frm/thread/aae22c59e5d218eb/8168efa560d04200
Field: LastName
Table: Your tablename
Update To: SplitName([Name],Chr(44),0)
Field: FirstName
Table: Your tablename
Update To: SplitName([Name],Chr(32),1)
Option Compare Database
Option Explicit
Public Function SplitName(strFullName As String, _
strCharCode As String, intElement As Integer) As String
On Error Resume Next
Dim strResult() As String
strResult = Split([strFullName], strCharCode)
SplitName = strResult(intElement)
End Function
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________