UK Post Codes - Extracting Area characters

AlexD

Registered User.
Local time
Today, 22:39
Joined
Sep 20, 2002
Messages
35
Hi,

I need to extract the first area character(s) from a table of UK postcodes,

i.e.
B from B7 8TY for Birmingham
LE from LE13 6PL for Leicester

I know any query/code is probably going to consist of ‘IsNumeric’, ‘Mid’ and ‘Left’ – just can’t get it to work.

Any help appreciated.

Alex
 
'On the fly' the code would something like:

FirstNumber = InString(Postcode,#)

FieldToPopulate = Left(Postcode,(FirstNumber-1))
 
You could also use

In code
Area = Left(PostCode, 1)
If Asc(Mid(PostCode, 2, 1)) >= 65 Then
Area = Area & Mid(PostCode, 2, 1)
End If


In a query
Left([PostCode],1) & IIf(Asc(Mid([PostCode],2,1))>=65,Mid([PostCode],2,1),"")


Smed
 
Create a query with the following Expression:

IIf(IsNumeric(Mid([PC],2,1)),Mid([PC],1,1),Mid([PC],1,2))

Where PC is the name of your postcode field

This goes in the Field Line of the query and is preceded by PC: or any chosen name.

It will return the first character or the first two depending on whether the second is numeric or not
 

Users who are viewing this thread

Back
Top Bottom