Solved Parse street address

Eljefegeneo

Still trying to learn
Local time
Yesterday, 22:50
Joined
Jan 10, 2011
Messages
899
I've gone brain dead for the last hour trying to figure out how to parse out the street address from a string. Tried InStr, Left, etc., but keep getting into dark places. As an example, the address might be:
1 State Street, Anywhere, NY 1001
I know how to get the city state and zip just can't figure out get out the 1 State Street. I know the answer is in front of me but I just can't see it
Thanks.
 
You could use InStr() to find the first comma along with the Left() function.
 
I'd probably use the Split() function these days.
 
Probably not what you really need here but I though I would mention one way is to parse addresses is with a Cartesian join to a list with all the streets types, (Street, Road, Crescent etc plus their abbreviations). Then use InStr() with this list to find what is before and after the street type. A space gets concatenated into the search expression.

I have a table with the StreetTypes and another field with their associated abbreviations. The fields can be unioned to get both the full type and abbreviations. The table can also be used to translate between the full type and abbreviation.

I use this technique on addresses without the suburb to get information about streets like "Some Street West" and find errors such as where the suburb has been put in the Address field.
 
If you use split() (based on the comma, say) then you will get an array with separate strings for each section in the address. We can come back to splitting the state and zip code later. The trouble is if some addresses have more than 2 commas, the split will not always be consistent. and you will still have a somewhat similar issue, although possibly more tractable.

ie
street address,
town/city,
state and zipcode

It also depends how many addresses you have as to whether you can subsequently tidy them up manually.

This is where @Galaxiom was going, to try to get the street address always in the same segment within the parsed address.

so this sort of code

Code:
dim s() as string  'an array of variable dimension
dim x as long

s = split("1 State Street, Anywhere, NY 1001",",") 'split the array into segments, based on comma separators
for x = 0 to ubound(s)  'the array is zero based. if there are no commas everything goes in s(0)
      msgbox("Segment: " & x & "   " & s(x))
next
 
Last edited:
While there are several viable approaches, this will always come back to the problem that people don't enter addresses uniformly. I have something that would address the problem with a bit of extra work.


This MIGHT be more than you want because it is a tool - but not the final answer. You could use it in a loop to pick apart pieces but the loop would then have to decide which piece you are working on. But it WOULD split text elements apart for you and I have not seen reliability issues with it.

In the final analysis, no matter what approach you take, the non-uniformity of input address styles will be the biggest problem.
 
Just a comment:

Many people have built careers by parsing names and addresses. There are many schemes, but as long as the application allows user to format input, no scheme is100%. There used to be a saying, you use a variety of schemes and pattern matches, but in the end it's "IEH - Eyeball". A manual review with human eyeballs to provide final inspection/correction.

**IEH - Eyeball is a play on words of the older IBM utilities IEHPROGM, IEFBR14, IEBGENER...
 
Thanks for all the suggestions. And yes I know that there are many different variations to address strings. Some use no commas, some use other characters, but at least most use the standard formula of: Street, City, State, Zip.

So I added a unbound text field, txtAddress to which I paste the address string. Then I use the following to first separate the street address and insert it into my Address field. Then I separate the remaining string into another string and then parse it using the code found on the Microsoft help page:

https://docs.microsoft.com/en-us/of...ow-to-parse-city-state-zip-to-separate-values

So now my code is:
Code:
 If Me.Dirty Then
     Me.Dirty = False
         End If
Dim strAdd As String
strAdd = txtAddress
         'First separate the street address from the string and put it in the Address Field
Me.Address = Left([strAdd], InStr([strAdd], ",") - 1)
           'Then separate the rest of the string to be parsed
Me.txtAddress = Mid([strAdd], InStr([strAdd], ",") + 1)

Dim City1 As String, State1 As String, Zip1 As String
     ParseCSZ txtAddress, City1, State1, Zip1
         City = City1
               State = State1
               Zip4 = Zip1
I know that if I worked hard and long enough I could probably modify the ParseCSZ module to include the street address, but the above works so I am done.
 
Something to be said for purchasing some sort of zipcode DB, that has all the addresses correctly stored.?
Over here we have a PAF product which is from our Post Office, but not cheap. :)

Colin (isladogs) has a similar product I believe now.(y)
 
Have you reviewed say 50-100 records to see if there is any sort of consistent pattern?
Perhaps code for a fairly consistent pattern , then check for next pattern ---eat the "elephant" in small pieces.

Yes, Gasman, same thing in Canada -- a $$$ subscription to CanadaPost.
 
Some use no commas, some use other characters, but at least most use the standard formula of: Street, City, State, Zip.
Then maybe you should consider the technique I mentioned in Post #4.
 
I'm not a huge fan of the USPS :(
I ordered something in the USA for delivery to a a dive buddy, to bring out to Cozumel the other year.
I put my name on it, so he could spot it straight away.

The USPS identified that there was no such name at that address and just returned it to the company???? :devilish: :devilish: :devilish:

Pat, you are concerned about Google, but that event is just too Big brother for me. :(
 
Isaac: I am searching the web based on a list of companies that might be interested in a certain service. The information is gleaned from either their web page or other related pages like Facebook, Linkedin, Manta, DnB, etc. So it really isn't in any special form. My code above allows me to copy an address from a web page, and then either paste it into a temporary field for automatic update to my Address, City, State, Zip fields if it is in the correct format, or paste it temporarily in my notes field so that I can quickly edit the address. Not rocket science, just plain hard work. I only wish the list was given to me with the addresses already in the spreadsheet so I could have manipulated it differently.

Some things you just to do the old tried and true way, cut and paste. I got a kick out of the diversion this post took. Sort of like a Next Door post where commenters got off topic. I got helped for which I am grateful.

But for me it is solved. Period.
 
Isaac: I am searching the web based on a list of companies that might be interested in a certain service. The information is gleaned from either their web page or other related pages like Facebook, Linkedin, Manta, DnB, etc. So it really isn't in any special form. My code above allows me to copy an address from a web page, and then either paste it into a temporary field for automatic update to my Address, City, State, Zip fields if it is in the correct format, or paste it temporarily in my notes field so that I can quickly edit the address. Not rocket science, just plain hard work. I only wish the list was given to me with the addresses already in the spreadsheet so I could have manipulated it differently.

Some things you just to do the old tried and true way, cut and paste. I got a kick out of the diversion this post took. Sort of like a Next Door post where commenters got off topic. I got helped for which I am grateful.

But for me it is solved. Period.
Cool. Honestly I was just curious. I did a project once that sounds a little similar, a guy had a service where he sent marketing emails to people of different trades - painters, drywall, electricians, etc. We were gathering email addressess off of yellowpages and similar websites. I can sympathize with a 1000 different data formats! Best of luck
 

Users who are viewing this thread

Back
Top Bottom