I’m trying to copy data from a field Owner into a new field PropertyOwner. The data is not consistent. Some is in this form: “HAMILTON, JEFF”. Some leaves out the space after the comma. Some records have no comma at all. My biggest headach, though, is dealing with all the variations of TRUST, LIVING TRUST and TR in the data. If I have a record that looks like this–“HAMILTON,TR”–it needs to come like “HAMILTON TR”. I’ve attached a zip file that contains a test table, update query and module that I think is close to what I need. It doesn’t deal properly with all the instances of the data. If someone can take a look and help fix my query or the module, or suggest some other alternative, I’d appreciate it.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Dealing with Name data (Access 2002)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Dealing with Name data (Access 2002)
- This topic has 29 replies, 5 voices, and was last updated 21 years, 4 months ago.
AuthorTopicWSjhamilton
AskWoody LoungerFebruary 4, 2004 at 1:13 am #400162Viewing 0 reply threadsAuthorReplies-
WSHansV
AskWoody Lounger -
WSjhamilton
AskWoody Lounger -
WSjhamilton
AskWoody Lounger -
WSjhamilton
AskWoody LoungerFebruary 4, 2004 at 4:48 pm #778883I spoke a bit too soon. When I tried it on a larger set of data, I noticed a couple of problems. First, the routine doesn’t deal properly with the following data: JOSLIN,BARBARA A ETAL. I get the following result: JOSLINE BARBARA A ET AL when it should be BARBARA A JOSLIN ETAL. I think we need to add a procedure that searches for the unique endings (TR, ETAL) and stores that to a variable, say ENDING. Then if there’s a comma, the string to the left of the comma gets stored to a variable LASTNAME. Then we store the string data to the right of the comma to a variable up to but excluding the unique ending string, if it exists, and call that FIRSTNAME. Then we rebuild the name as FIRSTNAME &” “& LASTNAME& ” “& ENDING. I don’t know how to code this and don’t know if I’m on the right track, but these are my thoughts.
Second, the procedure doesn’t deal properly with last names that begin with TR: AGUILAR,TRINIDAD or BRISENO,TRIFUNO & ANA TR (the last one’s really nasty). If we could deal with the first of the two it would be great. I can accept that a canned routine probably can’t deal with all possible versions of the data.
I’ve attached another copy of the database. Note that I added lines to the code trying to cover more versions of the ending, but it didn’t seem to help.
-
WScharlotte
AskWoody Lounger -
WSjhamilton
AskWoody LoungerFebruary 4, 2004 at 10:08 pm #779019Is such special handling something best left to an accomplished programmer (something I’m not) or are the solutions simple enough that I can understand and implement them? BTW, I have to deal with close to 40,000 records, of which a few hundred change each month. There’s no easy way to know each month which records may have these unique naming characteristics.
-
WSjhamilton
AskWoody LoungerFebruary 4, 2004 at 10:08 pm #779020Is such special handling something best left to an accomplished programmer (something I’m not) or are the solutions simple enough that I can understand and implement them? BTW, I have to deal with close to 40,000 records, of which a few hundred change each month. There’s no easy way to know each month which records may have these unique naming characteristics.
-
-
WScharlotte
AskWoody Lounger -
WSMarkD
AskWoody LoungerFebruary 4, 2004 at 9:04 pm #778991If interested, you can try using these functions:
Public Function GetNewText(ByVal strTxt As String) As String
On Error GoTo Err_HandlerDim strMsg As String
Dim intPos As Integer
Dim strTmp As String
Dim strFName As String
Dim strLName As String
Dim strSuffix As StringIf InStr(1, strTxt, “,”, 0) > 1 Then
intPos = InStr(1, strTxt, “,”, 0)
ElseIf InStr(1, strTxt, ” “, 0) > 1 Then
intPos = InStr(1, strTxt, ” “, 0)
Else
‘ No commas or spaces:
GetNewText = strTxt
Exit Function
End IfstrLName = Left$(strTxt, intPos – 1)
strTmp = Mid$(strTxt, intPos + 1)Do
intPos = InStr(1, strTmp, ” “, 0)
If intPos = 0 Then
If IsSuffix(strTmp) Then
strSuffix = strTmp
Else
strFName = strFName & ” ” & strTmp
End If
Exit Do
Else
If IsSuffix(strTmp) Then
strSuffix = strTmp
Exit Do
Else
strFName = strFName & ” ” & Left$(strTmp, intPos – 1)
strTmp = Mid$(strTmp, intPos + 1)
End If
End If
LoopGetNewText = Trim$(strFName & ” ” & strLName & ” ” & strSuffix)
Exit_Sub:
Exit Function
Err_Handler:
strMsg = “Error No ” & Err.Number & “: ” & Err.Description
Beep
MsgBox strMsg, vbExclamation, “ERROR MESSAGE”
Resume Exit_SubEnd Function
Private Function IsSuffix(ByRef strTmp As String) As Boolean
strTmp = UCase$(strTmp)
Select Case strTmp
Case “ETAL”, “ET AL”, “TR”, “TR ET AL”, “TR ETAL”, _
“TRUST”, “TRUST ET AL”, “TRUST ETAL”, _
“LIVING TR”, “LIVING TR ET AL”, “LIVING TR ETAL”, _
“LIVING TRUST”, “LIVING TRUST ET AL”, “LIVING TRUST ETAL”
IsSuffix = True
Case Else
IsSuffix = False
End SelectEnd Function
In test query, the GetNewText function returned correct results, using the table with sample data provided in your attachment. But if there are even more exclusions, exceptions, and deviations not included in the sample table, you will have to modify functions above accordingly. If modifying function, ensure that there will always be exit point for the Do loop so it does not loop endlessly. Also if any null fields in table use Nz function in query or else function will result in Invalid Use of Null error.
HTH
-
WSMarkD
AskWoody LoungerFebruary 4, 2004 at 9:04 pm #778992If interested, you can try using these functions:
Public Function GetNewText(ByVal strTxt As String) As String
On Error GoTo Err_HandlerDim strMsg As String
Dim intPos As Integer
Dim strTmp As String
Dim strFName As String
Dim strLName As String
Dim strSuffix As StringIf InStr(1, strTxt, “,”, 0) > 1 Then
intPos = InStr(1, strTxt, “,”, 0)
ElseIf InStr(1, strTxt, ” “, 0) > 1 Then
intPos = InStr(1, strTxt, ” “, 0)
Else
‘ No commas or spaces:
GetNewText = strTxt
Exit Function
End IfstrLName = Left$(strTxt, intPos – 1)
strTmp = Mid$(strTxt, intPos + 1)Do
intPos = InStr(1, strTmp, ” “, 0)
If intPos = 0 Then
If IsSuffix(strTmp) Then
strSuffix = strTmp
Else
strFName = strFName & ” ” & strTmp
End If
Exit Do
Else
If IsSuffix(strTmp) Then
strSuffix = strTmp
Exit Do
Else
strFName = strFName & ” ” & Left$(strTmp, intPos – 1)
strTmp = Mid$(strTmp, intPos + 1)
End If
End If
LoopGetNewText = Trim$(strFName & ” ” & strLName & ” ” & strSuffix)
Exit_Sub:
Exit Function
Err_Handler:
strMsg = “Error No ” & Err.Number & “: ” & Err.Description
Beep
MsgBox strMsg, vbExclamation, “ERROR MESSAGE”
Resume Exit_SubEnd Function
Private Function IsSuffix(ByRef strTmp As String) As Boolean
strTmp = UCase$(strTmp)
Select Case strTmp
Case “ETAL”, “ET AL”, “TR”, “TR ET AL”, “TR ETAL”, _
“TRUST”, “TRUST ET AL”, “TRUST ETAL”, _
“LIVING TR”, “LIVING TR ET AL”, “LIVING TR ETAL”, _
“LIVING TRUST”, “LIVING TRUST ET AL”, “LIVING TRUST ETAL”
IsSuffix = True
Case Else
IsSuffix = False
End SelectEnd Function
In test query, the GetNewText function returned correct results, using the table with sample data provided in your attachment. But if there are even more exclusions, exceptions, and deviations not included in the sample table, you will have to modify functions above accordingly. If modifying function, ensure that there will always be exit point for the Do loop so it does not loop endlessly. Also if any null fields in table use Nz function in query or else function will result in Invalid Use of Null error.
HTH
-
WSjhamilton
AskWoody Lounger -
WSMarkD
AskWoody LoungerFebruary 4, 2004 at 11:30 pm #779051Attached is modified version of the db you attached previously. The code I used is in Module1. The GetNewText function is declared as Public so it can be used in a query. Any function you write yourself, as opposed to the built-in functions provided by Access or by VBA, is usually described as a “user-defined” or “custom” function. For example of use in query, see “Test Query” and “Update Test Query” (update query) in attached db. If the data being processed each month is in same general format, it would not be hard to modify IsSuffix function Select Case statement to include other possibilities, but if the data is radically different there may be no single function that could effectively handle every possible case.
HTH
-
WSjhamilton
AskWoody Lounger -
WSjhamilton
AskWoody Lounger -
WSjhamilton
AskWoody Lounger -
WSjhamilton
AskWoody Lounger -
WSMarkD
AskWoody LoungerFebruary 4, 2004 at 11:30 pm #779052Attached is modified version of the db you attached previously. The code I used is in Module1. The GetNewText function is declared as Public so it can be used in a query. Any function you write yourself, as opposed to the built-in functions provided by Access or by VBA, is usually described as a “user-defined” or “custom” function. For example of use in query, see “Test Query” and “Update Test Query” (update query) in attached db. If the data being processed each month is in same general format, it would not be hard to modify IsSuffix function Select Case statement to include other possibilities, but if the data is radically different there may be no single function that could effectively handle every possible case.
HTH
-
-
WSjhamilton
AskWoody Lounger
-
-
WSHansV
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSHansV
AskWoody Lounger -
WSpatt
AskWoody LoungerFebruary 4, 2004 at 9:48 pm #779015Just like my old maths teacher in year 11. He as of the opinion that ‘mathmeticians are lazy, boys’ and I’m am going to teach you the short (as well as the long) way of solving maths problems. We were the 5B class and so he tookit as a bit of a challenge to outdo the 5A class. To cut a long story short, he did so easily.
Enough of this nostalgia, still a nice solution Hans.
-
WSpatt
AskWoody LoungerFebruary 4, 2004 at 9:48 pm #779016Just like my old maths teacher in year 11. He as of the opinion that ‘mathmeticians are lazy, boys’ and I’m am going to teach you the short (as well as the long) way of solving maths problems. We were the 5B class and so he tookit as a bit of a challenge to outdo the 5A class. To cut a long story short, he did so easily.
Enough of this nostalgia, still a nice solution Hans.
-
WSHansV
AskWoody Lounger
-
-
WSpatt
AskWoody Lounger -
WSjhamilton
AskWoody LoungerFebruary 6, 2004 at 5:29 pm #779950 -
WSjhamilton
AskWoody LoungerFebruary 6, 2004 at 5:29 pm #779951
-
-
WSHansV
AskWoody Lounger
-
-
WSjhamilton
AskWoody LoungerFebruary 4, 2004 at 4:48 pm #778884I spoke a bit too soon. When I tried it on a larger set of data, I noticed a couple of problems. First, the routine doesn’t deal properly with the following data: JOSLIN,BARBARA A ETAL. I get the following result: JOSLINE BARBARA A ET AL when it should be BARBARA A JOSLIN ETAL. I think we need to add a procedure that searches for the unique endings (TR, ETAL) and stores that to a variable, say ENDING. Then if there’s a comma, the string to the left of the comma gets stored to a variable LASTNAME. Then we store the string data to the right of the comma to a variable up to but excluding the unique ending string, if it exists, and call that FIRSTNAME. Then we rebuild the name as FIRSTNAME &” “& LASTNAME& ” “& ENDING. I don’t know how to code this and don’t know if I’m on the right track, but these are my thoughts.
Second, the procedure doesn’t deal properly with last names that begin with TR: AGUILAR,TRINIDAD or BRISENO,TRIFUNO & ANA TR (the last one’s really nasty). If we could deal with the first of the two it would be great. I can accept that a canned routine probably can’t deal with all possible versions of the data.
I’ve attached another copy of the database. Note that I added lines to the code trying to cover more versions of the ending, but it didn’t seem to help.
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows-Maintenance-Tool (.bat)
by
Alex5723
1 minute ago -
Windows 11 Insider Preview build 26200.5641 released to DEV
by
joep517
2 hours, 30 minutes ago -
Windows 11 Insider Preview build 26120.4250 (24H2) released to BETA
by
joep517
2 hours, 32 minutes ago -
Install Office 365 Outlook classic on new Win11 machine
by
WSrcull999
2 hours, 29 minutes ago -
win 10 to win 11 with cpu/mb replacement
by
aquatarkus
23 minutes ago -
re-install Windows Security
by
CWBillow
5 hours, 46 minutes ago -
WWDC 2025 Recap: All of Apple’s NEW Features in 10 Minutes!
by
Alex5723
9 hours, 27 minutes ago -
macOS Tahoe 26
by
Alex5723
3 hours, 41 minutes ago -
Migrating from win10 to win11, instructions coming?
by
astro46
10 hours, 40 minutes ago -
Device Eligibility for Apple 2026 Operating Systems due this Fall
by
PKCano
10 hours, 14 minutes ago -
Recommended watching : Mountainhead movie
by
Alex5723
22 hours, 59 minutes ago -
End of support for Windows 10
by
Old enough to know better
8 hours, 22 minutes ago -
What goes on inside an LLM
by
Michael Covington
7 hours, 26 minutes ago -
The risk of remote access
by
Susan Bradley
2 hours, 4 minutes ago -
The cruelest month for many Office users
by
Peter Deegan
1 hour, 10 minutes ago -
Tracking protection and trade-offs in Edge
by
Mary Branscombe
1 day, 1 hour ago -
Supreme Court grants DOGE access to confidential Social Security records
by
Alex5723
1 day, 7 hours ago -
EaseUS Partition Master free 19.6
by
Alex5723
8 hours, 28 minutes ago -
Microsoft : Edge is better than Chrome
by
Alex5723
1 day, 21 hours ago -
The EU launched DNS4EU
by
Alex5723
2 days, 9 hours ago -
Cell Phone vs. Traditional Touchtone Phone over POTS
by
280park
2 days ago -
Lost access to all my networked drives (shares) listed in My Computer
by
lwerman
2 days, 15 hours ago -
Set default size for pasted photo to word
by
Cyn
2 days, 21 hours ago -
Dedoimedo tries 24H2…
by
Cybertooth
2 days, 9 hours ago -
Windows 11 Insider Preview build 27871 released to Canary
by
joep517
3 days, 20 hours ago -
Windows 11 ad from Campaign Manager in Windows 10
by
Jim McKenna
1 day, 13 hours ago -
Small desktops
by
Susan Bradley
42 minutes ago -
Totally disable Bitlocker
by
CWBillow
2 days, 13 hours ago -
Phishers extract Millions from HMRC accounts..
by
Microfix
3 days, 17 hours ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
5 days ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.