Rich_Lovina
Registered User.
- Local time
- Today, 21:07
- Joined
- Feb 27, 2002
- Messages
- 225
My code splits a single field (NameAGS = “FirstName Middlename Lastname” into 3 separate fields “Inits” “1stname” and “Surname” inserted in an Append query.
Problem is we now have some mixed records in NameAGS such as AB Smith, in with Ann Smith or Ann Marie Smith, and the splitter is returning Inits=”A”, 1stName=”AB” and Surname=”Smith”.
What conditional code do I insert in the module to ensure that 2-char names return Inits=”AB” and that 1stName is blank?
Code is:
Function PrsIntls(NameAgs As String) As String
Dim SpPntr As Integer
Dim Intls As String
Intls = left(NameAgs, 1)
SpPntr = InStr(1, NameAgs, " ")
While SpPntr <> 0
Intls = Intls & Mid(NameAgs, SpPntr + 1, 1)
SpPntr = InStr(SpPntr + 1, NameAgs, " ")
Wend
PrsIntls = left(Intls, Len(Intls) - 1)
End Function
Function PrsLstNm(NameAgs As String) As String
Dim SpPntr As Integer
Dim LstNmPntr As Integer
SpPntr = InStr(1, NameAgs, " ")
LstNmPntr = 1
While SpPntr <> 0
LstNmPntr = SpPntr + 1
SpPntr = InStr(SpPntr + 1, NameAgs, " ")
Wend
PrsLstNm = Mid(NameAgs, LstNmPntr)
End Function
Function PrsFrstNm(NameAgs As String) As String
Dim SpPntr As Integer
SpPntr = InStr(1, NameAgs, " ")
'Intls = ""
If SpPntr <> 0 Then
'if there is a space then there is a first name or initial for a first name
PrsFrstNm = left(NameAgs, SpPntr - 1)
If Len(PrsFrstNm) = 1 Then
PrsFrstNm = ""
End If
End If
Thanks in advance, as have been away from this coding for some time.
Problem is we now have some mixed records in NameAGS such as AB Smith, in with Ann Smith or Ann Marie Smith, and the splitter is returning Inits=”A”, 1stName=”AB” and Surname=”Smith”.
What conditional code do I insert in the module to ensure that 2-char names return Inits=”AB” and that 1stName is blank?
Code is:
Function PrsIntls(NameAgs As String) As String
Dim SpPntr As Integer
Dim Intls As String
Intls = left(NameAgs, 1)
SpPntr = InStr(1, NameAgs, " ")
While SpPntr <> 0
Intls = Intls & Mid(NameAgs, SpPntr + 1, 1)
SpPntr = InStr(SpPntr + 1, NameAgs, " ")
Wend
PrsIntls = left(Intls, Len(Intls) - 1)
End Function
Function PrsLstNm(NameAgs As String) As String
Dim SpPntr As Integer
Dim LstNmPntr As Integer
SpPntr = InStr(1, NameAgs, " ")
LstNmPntr = 1
While SpPntr <> 0
LstNmPntr = SpPntr + 1
SpPntr = InStr(SpPntr + 1, NameAgs, " ")
Wend
PrsLstNm = Mid(NameAgs, LstNmPntr)
End Function
Function PrsFrstNm(NameAgs As String) As String
Dim SpPntr As Integer
SpPntr = InStr(1, NameAgs, " ")
'Intls = ""
If SpPntr <> 0 Then
'if there is a space then there is a first name or initial for a first name
PrsFrstNm = left(NameAgs, SpPntr - 1)
If Len(PrsFrstNm) = 1 Then
PrsFrstNm = ""
End If
End If
Thanks in advance, as have been away from this coding for some time.