Option Compare Database
Const conDelimiters = " "
Public Function fctExtractString(ByVal strIn As String, _
ByVal intPiece As Integer, _
Optional ByVal strDelimiter As String = conDelimiters) As String
Dim intPos As Integer
Dim intLastPos As Integer
Dim intLoop As Integer
Dim intPos1 As Integer
intPos = 0
intLastPos = 0
intLoop = intPiece
Do While intLoop > 0
intLastPos = intPos
intPos1 = InStr(intPos + 1, strIn, Left$(strDelimiter, 1))
If intPos1 > 0 Then
intPos = intPos1
intLoop = intLoop - 1
Else
intPos = Len(strIn) + 1
Exit Do
End If
Loop
If (intPos1 = 0) And (intLoop <> intPiece) And (intLoop > 1) Then
fctExtractString = ""
Else
fctExtractString = Mid$(strIn, intLastPos + 1, _
intPos - intLastPos - 1)
End If
End Function |