Re: Separating Addresses

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Chris2 (indanthrene.NOTVALID_at_GETRIDOF.yahoo.com)
Date: 03/17/04


Date: Wed, 17 Mar 2004 07:40:45 GMT


"Mike DeNuccio" <mike@denuccio.net> wrote in message
news:%23199ce%23CEHA.1544@TK2MSFTNGP09.phx.gbl...
I have a database of addresses that are inputed like this:

100 East Sunshine Street
200 East Sunshine Street, #400
3456 W Jones
1 Jones, Apt 2A

I need to divide this Address field into thee parts: House Number; Street;
Apt (only if it has an apartment which is indicated by the comma in the
field)

I know how to separate the House Number from the Address field:
Left([address],InStr([address]," "))
I know how to separate the Street from the Address if there is no apartment:
Right([address],(Len([address])-(InStr(1,[address]," "))))
I know how to separate the Apartment from the Address:
Trim(Right([address],(Len([address])-(InStr(1,[address],", ")))))

So here's my problem - if the Address has a apartment, I cannot get only the
Street to appear. Basically, I need everything in between the first space
and the comma to appear in a new field called Street. For example, in the
second example above, it would divide into this:

House Number: 200
Street: East Sunshine Street
Apt: #400

Seems easy, but I simply cannot figure out why it won't work.

The formula I was using for addresses with Apts is:
Trim(Mid([address],InStr([address]," ",InStr([address],", ")-1))) but this
does not return anything. I did this formula because in English what I was
trying to do was to say that the start character is the first space in the
field. The end character is the one with the comma (in the format
Mid([String], Start, End). Then I realized the formula is Mid(String,
Start, Length).

So I tried this: Trim(Mid([address],InStr([address],"
",Len([address])-InStr([address],", ")-1 ) ) )

Any help would be appreciated! If I am doing a very long version for the
ones I have, please correct those as well.
Thanks in advance. If possible, reply to me AND post.
#####################

Mike,

  I struggled for ten or twenty minutes with all the various arguments and
(), with no luck; this late at night, it all looks the same.

  Here it is encapsulated in VBA:

Public Function CaptureStreet(FullStreetAddress As String) As String

   Dim StreetName As String
   Dim FirstSpacePosition As Byte
   Dim LengthToLastSpace As Byte
   Dim ReversedFullStreetAddress As String
   Dim ReversedFirstSpacePosition As Byte
   Dim FullAddressLength As Byte

   FirstSpacePosition = InStr(FullStreetAddress, " ")
   ReversedFullStreetAddress = StrReverse(FullStreetAddress)
   ReversedFirstSpacePosition = InStr(ReversedFullStreetAddress, " ")

   FullAddressLength = Len(FullStreetAddress)
   LengthToLastSpace = FullAddressLength - _
                       FirstSpacePosition - _
                       ReversedFirstSpacePosition

   StreetName = Trim(Mid(FullStreetAddress, _
                         FirstSpacePosition, _
                         LengthToLastSpace))

   CaptureStreet = StreetName

End Function

  It worked for both the addresses shown above in the sample data, plus some
other basic combinations, like altering the length of the Street Number and
the Apartment Number, but that only amounted to five minutes testing, so it
may bear closer scrutiny.

Sincerely,

Chris O.



Relevant Pages

  • Re: Separating Addresses
    ... 100 East Sunshine Street ... Apt (only if it has an apartment which is indicated by the comma in the ... I know how to separate the Street from the Address if there is no apartment: ... Dim FirstSpacePosition As Byte ...
    (microsoft.public.access.modulesdaovba)
  • Re: Send meeting update only to new required attendees through VBA
    ... The problem that I am having is that the meeting update goes out to ... Dim Inbox As MAPIFolder ... Dim apt As Variant 'AppointmentItem ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Send meeting update only to new required attendees through VBA
    ... attendees but the early adopters could get dozens of meeting updates. ... Dim Inbox As MAPIFolder ... Dim apt As Variant 'AppointmentItem ...
    (microsoft.public.office.developer.outlook.vba)
  • Making an apt into a public calendar
    ... calendar, but I'd like to make an apt to the shared or public folder. ... Dim dteStart As Date ... Set objAppt = objOutlook.CreateItem ...
    (microsoft.public.outlook.program_vba)
  • Re: RTS Message by US Mail
    ... John Smith ... I've never seen Apartment listed first or the suite number listed ... 1234 ANYWHERE AVE APT 1 ... ANYTOWN, CA 12345-6789 ...
    (alt.marketing.online.ebay)