chavnick
11-02-2007, 01:01 PM
I have a table named "Patients" with a field named "Code" and another field named "Patient" which contains the full name (LastName space FirstName) "Chaviatsos Nick" for example.
I want to make an other table from the table "Patients" with three fields:
1. A field named "Code"
2. A field named "LastName" which will contain the Last Name of the field "Patient" of the table 'Patients" and
3. A field named "FrstName" which will contain the Frst Name of the field "Patient" of the table 'Patients"
How Can I manage this?
RuralGuy
11-02-2007, 02:48 PM
See if this function helps:
Public Function SplitName(InString As String, FirstName As Boolean) As String
Dim MyArray As Variant
MyArray = Split(InString, " ")
If FirstName Then
SplitName = MyArray(1)
Else
SplitName = MyArray(0)
End If
End Function
chavnick
11-03-2007, 08:10 AM
I get the error message No such a split sub or function.
RuralGuy
11-03-2007, 08:17 AM
Put the function in a standard module named basFunctions and try again. What version of Access are you using? Do you have any reference problems (http://www.accessmvp.com/djsteele/AccessReferenceErrors.html) in the db?
RuralGuy
11-03-2007, 10:36 AM
ac97 may not have the Split() function. See if you can use this function written by Bob Askew instead of mine.
Function ySplit(ByVal pTarget As String, pItem As String, _
Optional ShowLeft As Boolean = True) As String
'*******************************************
' Purpose: Splits a string to the left or
' right of pItem
' Coded by: raskew
' Inputs:
' 1) ySplit("The quick+ brown fox", "+", True)
' 2) ysplit("The quick+ brown fox", "+", False)
' Output:
' 1) The quick
' 2) brown fox
'*******************************************
Dim strLeft As String
Dim strRight As String
Dim n As Integer
n = InStr(pTarget, pItem)
If n = 0 Then
ySplit = ""
Else
ShowLeft = IIf(IsMissing(ShowLeft), True, ShowLeft)
strLeft = Left(pTarget, n - 1)
strRight = Mid(pTarget, n + 1)
ySplit = Trim(IIf(ShowLeft, strLeft, strRight))
End If
End Function
chavnick
11-04-2007, 10:27 PM
OK this is the solution. Thank you.:)
RuralGuy
11-05-2007, 02:35 AM
You're welcome. Glad I could help.