This function, copied to a standard module, will allow you to extract a word
or group of characters from a string, based on a designated position and a
designated delimiter.
To use, copy the function to a standard module. Save the module, ensuring
the module name is not the same as the function name. Call as shown in the
example:
Public Function PassbackAnyword(pstrText As String, pintword As Integer,
pstrdivider As String) As Variant
'Purpose: Given a string, a word and the divider,
' returns the specific word.
'Input: ? PassbackAnyword("1234*7890*8888", 2, "*")
'Output: 7890
Dim intLoop As Integer
Dim intPos As Integer
Dim intprev As Integer
Dim varstring As Variant
'Don't waste your time if the divider isn't in the string
If InStr(pstrText, pstrdivider) <> 0 Then
intPos = 1
intprev = 1
pstrText = pstrText & pstrdivider
For intLoop = 1 To pintword
intPos = InStr(intprev + 1, pstrText, pstrdivider)
If intPos <> 0 Then
If intLoop < pintword Then
intprev = intPos
End If
Else
intPos = intprev
End If
Next
varstring = Mid(pstrText, intprev, intPos - intprev)
If pintword > 1 And varstring <> "" Then
varstring = Right(varstring, Len(varstring) - 1)
End If
Else
'If it's the first word we want then it's all the string otherwise is
nothing
If pintword = 1 Then
varstring = pstrText
End If
End If
If varstring = "" Or varstring = pstrdivider Then
varstring = Null
End If
PassbackAnyword = varstring
End Function
HTH - Bob
In my example, I used a variable (x) and populated with a value. Reason: to
avoid having to
to write out long field names, such as [ASSET_TYPE].
So, if you were goiing that route, something like:
dim x as string
x = [ASSET_TYPE]
? mid(x, InStr(x, " ") + 1)
Bob
[quoted text clipped - 9 lines]