On 21 Feb 2005 09:43:58 -0800, Shelley wrote:
Hi everyone,
I am searching a way to read part of the data in the text field in a
form. As the length of the field is dynamic, I can't use the left or
right function. I need to read the first 2 words from the specific
control like:
Get "January 2005" from "January 2005 final", or "January 2005 test
samples", what I need is the first two words. What function I can use?
Any help will be greatly appreciated!
Thanks in advance!
Shelley
Is the second word always 4 characters (2004, 2005, etc.)?
Left([CombinedNames],(InStr([CombinedNames]," "))) &
Mid([CombinedNames],InStr([CombinedNames]," ")+1,4)
If the second word length varies:
Copy and paste the below code to a Module:
Public Function FindString(OldString) As String
' find the first 2 words within a string
Dim intX As Integer
Dim intY As Integer
intX = InStr(1, OldString, " ")
intY = InStr(intX + 1, OldString, " ")
FindString = Left(OldString, intY - 1)
End Function
==============
Call it from a query:
Exp:FindString([CombinedNames])
Or...
In an unbound control in a form or report:
= FindString([CombinedNames])
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.