Public Function GetPart(ByVal strTemp As String, ByVal strDelim As String, _
intPart As Integer) As String
On Error GoTo Err_GetPart
Dim intCounter As Integer
Dim intTotal As Integer
Dim intPos As Integer
Const Message1 = "A delimiter must be a single character."
Const Message2 = "Part exceeds delimited areas."
Const Buttons = vbExclamation + vbOKOnly
Const Title = "Error in Function GetPart()"
If Len(strDelim) <> 1 Then
MsgBox Message1, Buttons, Title
Exit Function
End If
If Right(strTemp, 1) <> ";" Then strTemp = strTemp & ";"
For intCounter = 1 To Len(strTemp)
If Mid(strTemp, intCounter, 1) = strDelim Then
intTotal = intTotal + 1
End If
Next intCounter
If intPart > intTotal Then
MsgBox Message2, Buttons, Title
Exit Function
End If
For intCounter = 1 To intPart
intPos = InStr(intPos + 1, strTemp, strDelim)
Next intCounter
GetPart = Mid(strTemp, intPos + 1, InStr(intPos + 1, strTemp, strDelim) - (intPos + 1))
Exit_GetPart:
Exit Function
Err_GetPart:
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_GetPart
End Function