Hi Guys
I need to split a postcode which I can do by removing the last 3 characters but that sometimes leaves a space. The field is:
ContactPostcode
RawPostCode: Left([ContactPostcode],Len([ContactPostcode]-3))
TrimmedPostCode: Trim(Left([RawPostCode],Len([RawPostCode]-3)))
But these return #Error, can anyone see why?
Kind Regards
Split PostCode
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Split PostCode
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78439
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Split PostCode
Move the closing parenthesis after -3 to after [ContactPostcode]:
RawPostCode: Left([ContactPostcode],Len([ContactPostcode])-3)
TrimmedPostCode: Trim(Left([RawPostCode],Len([RawPostCode])-3))
RawPostCode: Left([ContactPostcode],Len([ContactPostcode])-3)
TrimmedPostCode: Trim(Left([RawPostCode],Len([RawPostCode])-3))
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Split PostCode
Hmm, not quite the result I was after Hans?
You do not have the required permissions to view the files attached to this post.
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78439
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Split PostCode
Sorry, the latter should be
TrimmedPostCode: Trim(Left([ContactPostCode],Len([ContactPostCode])-3))
or
TrimmedPostCode: Trim([RawPostCode])
TrimmedPostCode: Trim(Left([ContactPostCode],Len([ContactPostCode])-3))
or
TrimmedPostCode: Trim([RawPostCode])
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78439
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Split PostCode
If you want to suppress the error value, use (for example)
RawPostCode: IIf(Nz([ContactPostCode])="",Null,Left([ContactPostcode],Len([ContactPostcode])-3))
TrimmedPostCode: IIf(Nz([ContactPostCode])="",Null,Trim(Left([ContactPostCode],Len([ContactPostCode])-3)))
RawPostCode: IIf(Nz([ContactPostCode])="",Null,Left([ContactPostcode],Len([ContactPostcode])-3))
TrimmedPostCode: IIf(Nz([ContactPostCode])="",Null,Trim(Left([ContactPostCode],Len([ContactPostCode])-3)))
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Split PostCode
Just the ticket Hans, that's very useful.
Thanks once more.
Cheers
Thanks once more.
Cheers
Cheers ...
Dave.
Dave.
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Split PostCode
Try:
=LEFT([ContactPostCode]& " ",FIND(" ",[ContactPostCode])-1)
Since one of your codes lacks a space, that one will be output in full.
=LEFT([ContactPostCode]& " ",FIND(" ",[ContactPostCode])-1)
Since one of your codes lacks a space, that one will be output in full.
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- Administrator
- Posts: 78439
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Split PostCode
Oops! Perhaps something along the lines of:
Split([ContactPostCode]& " "," ")(0)
Split([ContactPostCode]& " "," ")(0)
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- Administrator
- Posts: 78439
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Split PostCode
You'd have to wrap that in a VBA function, for Split doesn't work when used directly in a query.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14