You should be able to use the Instr() function to find the position of the
spaces (instr returns the position one string inside another... in this case
the string to find is " "), and then the Left() function will return the left
portion of the string, with the length being specified from the Instr
position of the second space.
Instr() returns only the first occurence of the string (your space), but
does allow us to set a position to start it at. So we'll have to call this
one twice... once to get the first space position, + 1, + the second space
position should tell us the correct number for the Left function.
Function GetFirstTwoWords(ByVal strInput As String) As String
On Error Goto Err_Proc
Dim iPos1 As Integer 'First space position
Dim iPos2 As Integer 'Second space position
'Cleanup any accidental double spaces
strInput = Replace(strInput, " ", " ")
'Find the position of the first space
iPos1 = Instr(1, strInput, " ")
'if no spaces were found exit the function
If iPos = 0 Then Goto Exit_Proc
'Find the position of the second space
iPos2 = Instr(iPos1 + 1, strInput, " ")
'Add the two together
iPos2 = iPos1 + iPos2
Exit_Proc:
'Get the left portion of the string
GetFirstTwoWords = Left(strInput, iPos2)
Exit Function
Err_Proc:
Msgbox Err.Num & vbTab & Err.Description
Resume Exit_Proc
End Function
hth
--
Jack Leach
www.tristatemachine.com
"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)