Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bold Access Problem, Splitting a Name Field

Status
Not open for further replies.

iain2003

MIS
Joined
Jan 16, 2003
Messages
9
Location
GB
Unsure if there is a solution to this but I am out of other options!
I once had some inherited code that allowed me to split a name field into title first name and surname regardless of the text string length, I recall that this was a relatively simpe piece of code but I cannot seem to replicate it. I have already posted this query in the Access VBA Modules forum with no luck so I thought I would try here as well, just in case.
 
Will this help, just a quick and dirty way to parse on a space?

Dim strTemp As String
Dim strLeft As String
Dim str1st As String
Dim str2nd As String
Dim str3rd As String
Dim intCnt As Integer
Dim intPos As Integer

strTemp = YourInputString
Do While InStr(strTemp, " ") > 1
intPos = InStr(strTemp, " ")
intCnt = intCnt + 1
strLeft = Trim$(Left$(strTemp, intPos))
strTemp = Trim$(Mid$(strTemp, intPos + 1))
Select Case intCnt
Case 1
str1st = strLeft
Case 2
str2nd = strLeft
Case 3
str3rd = strLeft
End Select
If Len(strTemp) > 0 Then
strTemp = strTemp & " " 'Keeps everything inside loop
End If
Loop

Good Luck!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top