• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

How to divide the address field into smaller parts

Dear Experts

I have an address field called ADDRESS. It has data in this form

1140 Rock Center Dr
38 Baja Harris fountain Rd
.....................................
....................................

What I want to do is divide this field into two field like this

Field1               Field
1140 Rock        Center Dr
38 Baja Harris   Fountain Rd

etc, etc

Can you please guide me through this

Thank You
0
syedasimmeesaq
Asked:
syedasimmeesaq
  • 18
  • 13
1 Solution
 
mbizupCommented:
Can you pinpoint a definite pattern in splitting up the addresses?  The pitfall in automating something like this is:

>38 Baja Harris fountain Rd  -- Should this be
field 1                 Field 2
------------------------------
38 Baja              Harris Fountain Rd   ?
38 Baja Harris     Fountain Rd            ??

How do you define the split so that it can consistently work for this and all other entries?

0
 
syedasimmeesaqAuthor Commented:
It should be

Field1                          field2

38 Baja Harris             Fountain Rd

What I think I should do is divide all the spaces to a seprate field and then somehow join the wanted ones back together.
BackGround : (Reason Why I am doing it):

I have two tables.

table1
ID
Name
Address

table2
Name
Address
Phone Number

Now table 2 I had imported from another data base and table 2 contains the phone number for some of the records in table 1. I want to match the table 2's address field to table 1's address field. But format is different. If I get them exactly same then I can do a query search to find the phone numbers from table2 and enter them in table1 where the address is same.

However, like always I have a problem here again.

The format of address in table 1 is like this

300 bridge creek road

and in table 2 they are using short names and stuff
like this

300 bridge creek Rd

or it could be

300 bridgecreek rd

now how can I solve this If you have a better idea I am willing to try it.

Thanks
0
 
mbizupCommented:
Are the Name fields similar?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
syedasimmeesaqAuthor Commented:
yea the name field is same. But the problem is that there are more than one similar names you know and I don't want to use name to merge it with phones from table cause than data will not be correct. I want to use name and address for the search of phone number. so if the name and address from table 1 matches table 2, then thats the phone number in table2 that we want in table1. Hope I explained it ok
Thanks
0
 
mbizupCommented:
Okay... How many records are we talking about?  A thought I had was to use the Name field and the first few characters (possibly the numeric portion) of the address field.  I would think that would give you the vast majority in a relatively simple way.  It would be easier than dividing the field and possibly more reliable...
0
 
thenelsonCommented:
Take a look at http://www.thenelson.name/#Set_UpperCase_Demo.  You can use it to program Road, road, ROAD to Rd, etc.  Use the routines to compare or in an updated query to change one of the tables then compare.

You might also be able to use soundex to do the comparison.  http://www.j-walk.com/ss/excel/tips/tip77.htm
0
 
syedasimmeesaqAuthor Commented:
Mbizup

 >>>>>A thought I had was to use the Name field and the first few characters (possibly the numeric portion) of the address field.

Thats a good idea. I was thinking about it too but I was not sure how to really do it
0
 
mbizupCommented:
Give this a shot...

This is an action query that will modify your table so please Make a Backup!

Add a field for the phone number to table1.
Make a new query with this as its SQL:

Update Table1 inner join table2 on Left(table1.addr, InStr(table1.addr, " ") - 1) = Left(table2.address, InStr(table2.address, " ") - 1) AND table1.Name = Table2.Name
SET table1.PhoneNumber = Table2.PhoneNumber

This will join the two tables where the Names and everything up to the first space in the address field match, and set the phone number field in table 1 equal to the phone number field in table2
0
 
mbizupCommented:
I changed table1.addr to table1.address as in your question, but do Check the otherfield names in the query I posted to make sure they match your application's field names.  

Update Table1 inner join table2 on Left(table1.address, InStr(table1.address, " ") - 1) = Left(table2.address, InStr(table2.address, " ") - 1) AND table1.Name = Table2.Name
SET table1.PhoneNumber = Table2.PhoneNumber
0
 
syedasimmeesaqAuthor Commented:
mbizup

Thank you for your code. WOuld it be possible to try to match the address up to the second space and not only the first space.
What I mean is this

Carlos        3456 Montview park dr          

and if it can match 3456 Montview  instead of only 3456

thanks
0
 
syedasimmeesaqAuthor Commented:
Any idea???

Thanks
0
 
mbizupCommented:
Sorry it's taken me so long to respond...

add this to a module:

Public Function FirstTwoParts(s As String) As String
    Dim arr As Variant    
    arr = Split(s, " ")
    FirstTwoParts = arr(0) & arr(1)
End Function

then modify the query like this:

Update Table1 inner join table2 on FirstTwoParts(table1.Address) = FirstTwoParts(table2.Address) AND table1.Name = Table2.Name
SET table1.PhoneNumber = Table2.PhoneNumber

This should compare the first tow words in the addressfield in both tables.  Make a backup and give it a try.


0
 
syedasimmeesaqAuthor Commented:
it gives me a Debug error

"Subscript out of range"

and highlights this

FirstTwoParts = arr(0) & arr(1)

Thanks
0
 
syedasimmeesaqAuthor Commented:
When I tried it again, it stopped with a warnning of "DATA MISMATCH CRITERIA"

Thanks
0
 
syedasimmeesaqAuthor Commented:
Could it be because PHONE field in table1 is indexed and in table2 it is not?..Same with Name fields.

Thanks
0
 
syedasimmeesaqAuthor Commented:
I did indexing. It still hangs up after 2 minutes with this warning

"Data type mismatch in criteria expression"

thanks

0
 
mbizupCommented:
I think the first error might be because of blank addresses, or addresses with no spaces.  try this:

Public Function FirstTwoParts(s As String) As String
    Dim arr As Variant
    if nz(s,"") = ""  then
         FirstTwoParts = ""
         exit function
    end if
    arr = Split(s, " ")
    FirstTwoParts = arr(0) & arr(1)
End Function
0
 
syedasimmeesaqAuthor Commented:
I tried
Public Function FirstTwoParts(s As String) As String
    Dim arr As Variant
    if nz(s,"") = ""  then
         FirstTwoParts = ""
         exit function
    end if
    arr = Split(s, " ")
    FirstTwoParts = arr(0) & arr(1)
End Function

 and it still is giving this error

"Data type mismatch in criteria expression"

Thanks


0
 
syedasimmeesaqAuthor Commented:
I went ahead and deleted 5479 records with empty address field in table2. Now it gives me this error

"Subscript out of range"

and highlights this

FirstTwoParts = arr(0) & arr(1)

Thanks
0
 
syedasimmeesaqAuthor Commented:
It also says in the warning box,
Runtime Error 9

I thought may be you need this info

Thanks
0
 
mbizupCommented:
The other problem I mentioned ealier might be addresses with no spaces.  The error handling in this code should take care of that:

Public Function FirstTwoParts(s As String) As String
    On Error GoTo Oh_No
    Dim arr As Variant
    If Nz(s, "") = "" Then
         FirstTwoParts = ""
         Exit Function
    End If
    arr = Split(s, " ")
    FirstTwoParts = Trim(arr(0)) & " " & Trim(arr(1))
    Exit Function
Oh_No:
    FirstTwoParts = Trim(s)  
End Function

I believe the data type mismatch is happening in the query. Make sure that the phone numbers are of the same data type in both table1 and table2.  
0
 
syedasimmeesaqAuthor Commented:
When I use the above code,

The program just keep running and nothing happens and I have to restart computer. It doesn't hangup but it looks like its not doing anything in access window and if I try to go to anyother program and want to get back to access window I can't. Also the hard drive light doesn't blink so I think it just hangsup??? However in the ctr-alt-delete windo, it shows access as running....Any idea whats happening,

Thanks
0
 
mbizupCommented:
>Any idea whats happening
I'm not sure.  I tested that code before posting it, and it worked fine...  If it "just keeps running", have you checked your table1 to see what if any updates were made?  Did you run the code through the Update Query I gave you, or did you run it from the VB editor?
0
 
syedasimmeesaqAuthor Commented:
I ran it through update query you gave me. I also checked the table and there were no records found in that table. I appreciate your quick response as I need it before meeting tomorrow.

Do you think it is because there could be more than one similar records in either of the 2 tables?

Thanks

Asim
0
 
syedasimmeesaqAuthor Commented:
can we do something like
msgbox 'if record is added

for each record that is added so I can check for few records and see if it is even working.

Thanks
0
 
syedasimmeesaqAuthor Commented:
ok my friend, it did work. I think there was some problem with my laptop. When I changed it to desktop, it worked. I do have one doubt about data integrity and I need an opinion from an expert like yourself. How accurate you think it matched the 2 files. There are 300,000+ records so I can check each and every one manually but I will check a random sample. But your hones opinion will count a lot.

Thanks

0
 
mbizupCommented:
>300,000+ records

LOL!! I had a sneaking suspicion.  Yes... that will require plenty of time and patience.  Since you shut down the computer, run it again, walk away and just let it do it's thing.  I think the integrity will be very good .  The example you posted earlier would be a possible stumbling block where you are matching the first two words instead of just the number:

300 bridge creek Rd  Versus 300 bridgecreek rd

One has a space in the road name, the other doesn't.  There is also the potential for missed telephone numbers where one table has a typo in the road name and the other does not.  Other than that, the match is case insensitive and should work very well.  The Soundex URL that Nelson posted is worth checking into as well (I'm not very familiar with it myself), it may help out with possible typo issues.

Anyhow It's late here, and my eyes are slamming shut.  I will check back in tomorrow.
0
 
mbizupCommented:
> Since you shut down the computer, run it again, walk away and just let it do it's thing
Rereading  your last post, It sounds like you already ran it again and let it complete its job?
0
 
mbizupCommented:
One more quick note on the reliability.  The typos that I mentioned as potential issues will result in the phone number not being "picked up" in table1.  You won't get the phone number mismatched with the wrong person.  So  even if you run into a few typos those records should not be any worse off than they were before.
0
 
syedasimmeesaqAuthor Commented:
ok thank you so much.
You are truely a great person

Thanks
0
 
mbizupCommented:
You're very welcome! Good luck with your project.
0
 
syedasimmeesaqAuthor Commented:
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 18
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now