L
Leslie Isaacs
Bob
This is obviously proving problematic: now the A is accepted in the first
position, but I think each of the following 'rules' is being ignored:
The only letters to appear in the third position are A, B, C, D, E, F,
G, H, J, K, S, T, U and W.
The only letters to appear in the fourth position are A, B, E, H, M,
N, P, R, V, W, X and Y.
The second half of the Postcode is always consistent numeric, alpha,
alpha format and the letters C, I, K, M, O and V are never used.
Is this a simple matter to fix?
As ever, I'm extremely grateful for all your help with this: it'll be
great when it's perfect!
Les
This is obviously proving problematic: now the A is accepted in the first
position, but I think each of the following 'rules' is being ignored:
The only letters to appear in the third position are A, B, C, D, E, F,
G, H, J, K, S, T, U and W.
The only letters to appear in the fourth position are A, B, E, H, M,
N, P, R, V, W, X and Y.
The second half of the Postcode is always consistent numeric, alpha,
alpha format and the letters C, I, K, M, O and V are never used.
Is this a simple matter to fix?
As ever, I'm extremely grateful for all your help with this: it'll be
great when it's perfect!
Les
Bob Phillips said:Well this works for those but it is not really my code so I may break
something else.
This code as it stands allows A and any second letter except I,J,Z.
What about A#, is that valid?
Function ValidatePostCode(ByVal PostCode As String)
Dim Parts() As String
PostCode = UCase$(PostCode)
Parts = Split(PostCode)
If PostCode = "GIR 0AA" Or PostCode = "SAN TA1" Or _
(Parts(1) Like "#[A-Z][A-Z]" And _
(Parts(0) Like "[A-Z]#" Or _
Parts(0) Like "[A-Z]#[0-9A-Z]" Or _
Parts(0) Like "[A-Z][A-Z]#" Or _
Parts(0) Like "[A-Z][A-Z]#[0-9A-Z]")) Then
ValidatePostCode = (Parts(0) Like "[BEGLMSW]#*" Or _
Parts(0) Like "A[ABCDEFGHKLMNOPQRSTUVWXY]#*" Or _
Parts(0) Like "B[ABDHLNRST]#*" Or _
Parts(0) Like "C[ABFHMORTVW]#*" Or _
Parts(0) Like "D[ADEGHLNTY]#*" Or _
Parts(0) Like "E[CHNX]#*" Or _
Parts(0) Like "F[KY]#*" Or _
Parts(0) Like "G[LU]#*" Or _
Parts(0) Like "H[ADGPRSUX]#*" Or _
Parts(0) Like "I[GPV]#*" Or _
Parts(0) Like "K[ATWY]#*" Or _
Parts(0) Like "L[ADELNSU]#*" Or _
Parts(0) Like "M[EKL]#*" Or _
Parts(0) Like "N[EGNPRW]#*" Or _
Parts(0) Like "O[LX]#*" Or _
Parts(0) Like "P[AEHLOR]#*" Or _
Parts(0) Like "R[GHM]#*" Or _
Parts(0) Like "S[AEGKLMNOPRSTWY]#*" Or _
Parts(0) Like "T[ADFNQRSW]#*" Or _
Parts(0) Like "W[ACDFNRSV]#*" Or _
Parts(0) Like "UB#*" Or _
Parts(0) Like "YO#*" Or _
Parts(0) Like "ZE#*" And _
(Parts(1) Like "*#[!CIKMOV][!CIKMOV]"))
End If
End Function
--
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my
addy)
Leslie Isaacs said:Bob
Any of the AANN ANN formats - .e.g. AC47 7BT should be OK, but is
rejected.
Les
Bob Phillips said:Les,
It allows AB1 1MA, AL1 1MA but no other A* combination. What should it
allow starting with A?
--
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my
addy)
Bob
Many thanks for this.
I have tested lots of postcodes with your code, and the only problem I
have been able to find so far is that it does not allow an A in the
first position (which should be valid). Again, I wish I could
understand the code sufficiently to know how to amend it for this, but
I can't get it!
Thanks for not giving up on me!
Les
Until Rick signs in, try this amendment
Function ValidatePostCode(ByVal PostCode As String)
Dim Parts() As String
PostCode = UCase$(PostCode)
Parts = Split(PostCode)
If PostCode = "GIR 0AA" Or PostCode = "SAN TA1" Or _
(Parts(1) Like "#[A-Z][A-Z]" And _
(Parts(0) Like "[A-Z]#" Or _
Parts(0) Like "[A-Z]#[0-9A-Z]" Or _
Parts(0) Like "[A-Z][A-Z]#" Or _
Parts(0) Like "[A-Z][A-Z]#[0-9A-Z]")) Then
ValidatePostCode = (Parts(0) Like "[BEGLMSW]#*" Or _
Parts(0) Like "A[BL]#*" Or _
Parts(0) Like "B[ABDHLNRST]#*" Or _
Parts(0) Like "C[ABFHMORTVW]#*" Or _
Parts(0) Like "D[ADEGHLNTY]#*" Or _
Parts(0) Like "E[CHNX]#*" Or _
Parts(0) Like "F[KY]#*" Or _
Parts(0) Like "G[LU]#*" Or _
Parts(0) Like "H[ADGPRSUX]#*" Or _
Parts(0) Like "I[GPV]#*" Or _
Parts(0) Like "K[ATWY]#*" Or _
Parts(0) Like "L[ADELNSU]#*" Or _
Parts(0) Like "M[EKL]#*" Or _
Parts(0) Like "N[EGNPRW]#*" Or _
Parts(0) Like "O[LX]#*" Or _
Parts(0) Like "P[AEHLOR]#*" Or _
Parts(0) Like "R[GHM]#*" Or _
Parts(0) Like "S[AEGKLMNOPRSTWY]#*" Or _
Parts(0) Like "T[ADFNQRSW]#*" Or _
Parts(0) Like "W[ACDFNRSV]#*" Or _
Parts(0) Like "UB#*" Or _
Parts(0) Like "YO#*" Or _
Parts(0) Like "ZE#*" And _
(Parts(1) Like "*#[!CIKMOV][!CIKMOV]"))
End If
End Function
--
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my
addy)
Rick
OK - my mistake - sorry!
Using the new code you gave however still seems to be allowing A3Z
3AA, etc - i.e. with a prohibited Z (and other prohibited letters) in
the 3rd position.
Does this happen at your end?
Thanks as ever
Les
in message The amended code is now working ... except that it seems to be
rejecting every postcode that I eneter (even my own!).
I wish I could understand the code a little better - then I could
try to see why this is happening!
The function appears to be working fine here. You are putting the
function in a Module that you add inside the VBA editor
(Insert/Module from its menu bar), right?
Rick