Postcodes - Return only TEXT before numbers (1 Viewer)

PG2015

Registered User.
Local time
Today, 19:05
Joined
Feb 16, 2015
Messages
21
Hi,

I have a number of short postcodes ie

S43
GU10
ME8

etc etc

I want a run query to return only first characters before the numbers ie..
S
GU
ME

Any ideas please? :banghead:
 

vbaInet

AWF VIP
Local time
Today, 19:05
Joined
Jan 22, 2010
Messages
26,374
Write a function to loop through each letter. Some aircode:
Code:
strPostCode = "S43"

For x = 1 to Len(strPostCode)
    If Mid(...) Like "[a-zA-Z]" Then
        ... concatenate here ...
    Else
        Exit For
    End If
Next
You can also use the Asc() function in place of the Like check.

Then use that function in your query.
 

namliam

The Mailman - AWF VIP
Local time
Today, 20:05
Joined
Aug 11, 2003
Messages
11,695
Use the instr and Left (possibly mid) functions...

I.e. instr(1,"ABCDEFGH...", left("GU10",1) )

Will return 7 indicating a character there

Or you can reverse it

i.e. instr(1,"12345...", left("GU10",1) )
Will return 0 indicating it isnt a number (thus has to be a character)
 

PG2015

Registered User.
Local time
Today, 19:05
Joined
Feb 16, 2015
Messages
21
Thanks everyone for your help..

I think I have cheated - not sure its good but seems to work :eek:

SHORTPOSTCODE: (Left([postcode],1) & IIf(IsNumeric(Right(Left([postcode],2),1))=False,Right(Left([postcode],2),1),""))
 

vbaInet

AWF VIP
Local time
Today, 19:05
Joined
Jan 22, 2010
Messages
26,374
Or:
Code:
SHORTPOSTCODE: Left([Field], IIf(IsNumeric(Mid([Field], 2)), 1, 2))
... however, I'm not sure if all UK postcodes (I'm guessing this is what you're working with) have either 1 or 2 letters in the first part that was why I mentioned looping through.
 

Users who are viewing this thread

Top Bottom