Hi, so i need to tri down the postcodes from a table so they match another table the issue is that one table has the full postcode like AB1 8TT and the other table just has AB. I think trim maybe the answer but unsure if that will work?
using this
PostcodeRev: Left([Postcode],2)
oh yes you are correct it does not work when the post code is just B or G, how do i do that to get it to work?Some musings
It's tricky depending on what is in your "trimmed" postcode table, and the post code you have to check.
Does the selected post code affect things like a radial cost rate/distance, so you need to get the right one.
I mean for AB - Aberdeen, you might have these postcodes
AB
AB1
AB2
...
AB11
AB12
Assuming you have a full post code to check
a) does it have a space , in which case you can take the chars up to the space
b) if not, maybe take the length all but the last 3 chars.
(I think UK codes have a left part, and than always NXX for the last three chars, but I am not sure)
you could start trimming chars from the post code until you find a match
So - given a full postcode such as AB114XZ test these
AB114XZ
AB114X
AB114
AB11 - stop at a match.
BUT there can be problems.
for a post code such as AB1 1ER, this will stop at AB1
whereas for the same code presented as AB11ER it stops at AB11 (hence suggestion b) above to pre-process the post code).
Everything can get tricky with "fuzzy"/badly formed data.
oh so my method doesnt work for say G or B postcodesYou are trying to retrieve the postcode area from the full postcode. This is the non-numeric part of the postcode before the space.
As Dave indicated this is usually two letters e.g. AB or BS but can be just one letter e.g. G, B etc
Similarly the numbers can be one or two numbers before the space ...and to make matters worse you can have e.g. EC1A....which breaks all the standard rules.
Retrieving what you want can be messy as a result.
If it helps, I can provide a table of all 125 UK postcode areas for you to compare against.
NOTE the easy bit is that after the space is ALWAYS a number followed by two letters
Ok this is the working optionAs per Colin's post - this isn't quite a straightforward as you may initially think.
Take him up on giving you the list, when I created mine (years ago) it took a considerable amount of manual work after the initial automatic bits.
Ok this is the working option
Left([PostCode],1) & IIf(Asc(Mid([PostCode],2,1))>=65,Mid([PostCode],2,1),"")
function postzone(postcode as string) as string
postzone = Left([PostCode],1) & ... your concatenation code, which I can't post for some reason.
end function
Thank you but same issue still getting the daa type mismatch in criteria expressiontry this
sorry - unable to post a code fragment. I will try later.
Maybe you can't use mid() and asc() within a query. Use a function. You need to test for a blank postcode, and a bad single char postcode
Use a function. You need to test for a blank postcode, and a bad single char postcode
Code:function postzone(postcode as string) as string postzone = Left([PostCode],1) & ... your concatenation code, which I can't post for some reason. end function
then just put this in your query
=postzone([postcode])