I'm a Novice User using Access 2003
Tables are via ODBC (i.e., cannot alter fields)
I have a report that uses the field OrderRepName (text string) and is formatted as lastname, firstname, middleinitial (No prefixes or suffixes, etc.). Sometimes the field is blank and sometimes there is no middle initial.
I found the following code on the Internet and it seems like it will work except I get an error message regarding Null values, and it doesn't seem to handle middle initials. (I modified it slightly replacing the word "underscore " with "space").
Can someone help me modify the following code, or suggest something else?
This first function called ParseFirstComp will return the portion of the string before the space. The second function called ParseSecondComp will return the portion of the string after the space.
Next, you'll need to use this function in your query
(picture - but it won't let me paste it into this posting)
In the example above, we've used both functions to parse a field called Name. You will need to substitute your field name with the ParseFirstComp and ParseSecondComp functions. So we've typed ParseFirstComp([Name]) in the first field and ParseSecondComp ([Name]) in the second field. Access assigns the field name of "Expr1" and "Expr2" - you can always overwrite this.
Now, when we run the query, we'll get the following results:
(Picture - but it won't let me paste it into this posting)
Thanks,
Krazy
Tables are via ODBC (i.e., cannot alter fields)
I have a report that uses the field OrderRepName (text string) and is formatted as lastname, firstname, middleinitial (No prefixes or suffixes, etc.). Sometimes the field is blank and sometimes there is no middle initial.
I found the following code on the Internet and it seems like it will work except I get an error message regarding Null values, and it doesn't seem to handle middle initials. (I modified it slightly replacing the word "underscore " with "space").
Can someone help me modify the following code, or suggest something else?
Code:
Function ParseFirstComp(pValue) As String Dim LPosition As Integer 'Find postion of space LPosition = InStr(pValue, " ") 'Return the portion of the string before the space If LPosition > 0 Then ParseFirstComp = Left(pValue, LPosition - 1) Else ParseFirstComp = "" End If End Function Function ParseSecondComp(pValue) As String Dim LPosition As Integer 'Find postion of space LPosition = InStr(pValue, "_") 'Return the portion of the string after the space If LPosition > 0 Then ParseSecondComp = Mid(pValue, LPosition + 1) Else ParseSecondComp = "" End If End Function
Next, you'll need to use this function in your query
(picture - but it won't let me paste it into this posting)
In the example above, we've used both functions to parse a field called Name. You will need to substitute your field name with the ParseFirstComp and ParseSecondComp functions. So we've typed ParseFirstComp([Name]) in the first field and ParseSecondComp ([Name]) in the second field. Access assigns the field name of "Expr1" and "Expr2" - you can always overwrite this.
Now, when we run the query, we'll get the following results:
(Picture - but it won't let me paste it into this posting)
Thanks,
Krazy
Comment