Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a piece of string

Status
Not open for further replies.

bitg07

IS-IT--Management
Jan 3, 2002
3
CA
How do I use the LEFT function to return all characters on the left of a specific character. For example: I have a string that looks like "text1:text2" where text1 varies in length. What is the expression to return text1 (everything before the ":"? All help is appreciated as always.
 
Use the InStr function to find the location of the ":" in your string and then use the Left function to take the string left of the colon (now that you know its numerical location. Both functions are explained in the Access help file.

Hope that helps!
 
Use the InStr function to find the location of the ":" in your string and then use the Left function to take the string left of the colon (now that you know its numerical location. Both functions are explained in the Access help file.

Hope that helps!
 
Hi!

Try this:

text1 = Left(YourString, InStr(YourString, ":") - 1)

Unless you are positive there is a : in the string you probably should test for it first:

Dim lngPostition As Long

lngPostition = InStr(YourString, ":")
If lngPostition = 0 Then '0 means no colon was found
text1 = YourString
Else
text1 = Left(YourString, lngPosition - 1)
End If

hth
Jeff Bridgham
bridgham@purdue.edu
 
look into "Split" function. Somewhat easier (IMHO)

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top