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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting part of a string for each record in a query result

Status
Not open for further replies.

weezles

Technical User
Jul 18, 2003
81
GB
hiya

I'm trying to extract the first part of a postcode (before a space) for each record in a query result (alternatively in a table and create query later on these results).

i have the following code which works for a single string but how do I do it for each record?
Code:
Dim strPostcode as string
Dim intPosition as integer
Dim strFirstPart as string

strPostcode = "EH15 1JJ"
intPostition = InStr(strPostcode, " ")

strFirstPart = Left$(strPostcode, intPosition)

Thanks

Lou
 
thats great thanks.

is there any way i can handle nulls?

Lou
 
Hi

Depends what you want to do but maybe:

strFirstPart: Left$((Nz(strPostcode,"- "), InStr(Nz(strPostCode,"- "), " "))

see Nz() in help


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
If you want to preserve the Null:
strFirstPart: IIf(IsNull(strPostcode), Null, Left(strPostcode, InStr(Nz(strPostcode," "), " ")-1))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top