A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

A couple of text parsing questions



 
 
Thread Tools Display Modes
  #1  
Old July 10th, 2008, 03:00 PM posted to microsoft.public.access.queries
scubadiver
external usenet poster
 
Posts: 1,673
Default A couple of text parsing questions


Question no.1

Eg, the following

NORCREST, , WOODSIDE ROAD, , , BANCHORY, KINCARDINESHIRE, AB314EN

How do I get "AB314EN" on its own ie. just the text after the last comma.


Question no.2

Each postcode has either 3/4 characters followed by 3 characters. So in the
above example I need a space to get:

AB31 4EN


I could parse the text in Excel and re-import but I thought I would ask
anyway.
  #2  
Old July 10th, 2008, 03:21 PM posted to microsoft.public.access.queries
scubadiver
external usenet poster
 
Posts: 1,673
Default A couple of text parsing questions


I've done it.

Replace(LTrim(Right([query1].[address],7))," ","")


  #3  
Old July 10th, 2008, 03:34 PM posted to microsoft.public.access.queries
fredg
external usenet poster
 
Posts: 4,386
Default A couple of text parsing questions

On Thu, 10 Jul 2008 07:00:00 -0700, scubadiver wrote:

Question no.1

Eg, the following

NORCREST, , WOODSIDE ROAD, , , BANCHORY, KINCARDINESHIRE, AB314EN

How do I get "AB314EN" on its own ie. just the text after the last comma.

Question no.2

Each postcode has either 3/4 characters followed by 3 characters. So in the
above example I need a space to get:

AB31 4EN

I could parse the text in Excel and re-import but I thought I would ask
anyway.


Using Access 2000 or newer:

To get the text after the last comma is easy in a query (it appears
there is actually a comma and space before the final text):

Mid([FieldName],InStrRev([FieldName],",")+2)

To place a space within that last text, for me, it would be best to
write a User Defined Function and call the function from the query.
Copy the below code into a module:

Function GetPostCode(strIn As String) As String
Dim newString As String
newString = Mid(strIn, InStrRev(strIn, ",") + 2)
If Len(newString) = 6 Then
newString = Left(newString, 3) & " " & Right(newString, 3)
Else
newString = Left(newString, 4) & " " & Right(newString, 3)
End If
GetPostCode = newString
End Function
-------------
Then call it from the query:
GetPostCode([FieldName')








--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #4  
Old July 10th, 2008, 03:37 PM posted to microsoft.public.access.queries
Michel Walsh
external usenet poster
 
Posts: 2,404
Default A couple of text parsing questions

You could also have used

InStrRev( address, "," )


to find the position of the last coma (if there is one)


Vanderghast, Access MVP


"scubadiver" wrote in message
...

I've done it.

Replace(LTrim(Right([query1].[address],7))," ","")




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:31 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.