This is tough and it will never be correct in every case.
Spencer, Jr., John and Susan
LastName: Left(YourField, Instr(1,Yourfield,",") -1)
RestOfName: Mid(YourField, Instr(1,YourField,",") + 1)
Combine those
Trim(Mid(YourField, Instr(1,YourField,",")+1)) & " " &
Trim(Left(YourField, Instr(1,Yourfield,",")-1))
Now, to change & to AND and etux to and
Replace(Replace(Trim(Mid(YourField, Instr(1,YourField,",")+1)) & " " &
Trim(Left(YourField, Instr(1,Yourfield,",")-1))," & ", " and "), " etux
", " and ")
Ain't that beeeyoootiful! and it will fail if there is no comma or if
the value
in the name field happens to be null
I would rather use a custom function to do this. Untested
Public Function fMakeName(sNameIn)
Dim strOut as String
If Len(trim(sNameIn & "") = 0) Then
fMakeName = sNameIN
ElseIf Instr(1,sNameIn,",") = 0 then
fMakeName = sNameIn
Else
strOut = Trim(Mid(sNameIn, Instr(1,sNameIn,",") + 1))
strOut = Replace(strOut," etux ", " and ")
strOut = Replace(strOut," & ", " and ")
strOut = strOut & " " & Trim(Left(YourField,
Instr(1,Yourfield,",") -1))
fMakeName = strOut
End If
End Function
Copy that into a module and save it (module name must be different then
function name).
In the query or on the report you should be able to call the function.
In query
Field: FullName: fMakeName([Yourtablename].[YourfieldName])
Trying to make these look like real names:
Smith, John Etux Gertrud
Jones, Anita A Etvir Charles W
Richards, Allen M & Linda L
I want them to look like:
John and Gertrud Smith
Problem is, there is no predicting if there will be an initial or not,
or an
"etux" or not, etc. There is always a last name and comma.
Anyone have any ideas? I can get around with text manipulation but
this is
beyond me! Thanks for any help.
Ronda