Solved

Split 10 digit phone numbers into 2 fields

Posted on 2002-04-06
5
320 Views
Last Modified: 2008-03-06
I need help with a query to run in Access. I have a field called "phone" in a table called "NewMasterName". This contains phone numbers in two different formats some with area code and some without. I need to split these.

one is 1112223333
the other is 2223333

I need to break this down in this way, if the field contains only the 7 digit phone number leave it alone, BUT if it contains a 10 digit phone number I need to pull the first three digits and move them into a field called "AreaCode" in the same table. Can somebody give me a simple query to do this?
0
Comment
Question by:DavidNPD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Accepted Solution

by:
innosys earned 50 total points
ID: 6923211
you can use an update query to do this
UPDATE NewMasterName SET NewMasterName.phone = IIf(Len([phone])=10,Mid([phone],4,10),[phone]), NewMasterName.AreaCode = IIf(Len([phone])=10,Mid([phone],1,3),"");
0
 
LVL 5

Expert Comment

by:hafeezmca
ID: 6923443
Try out this simple procedure

UPDATE NewMasterName SET NewMasterName.phone = IIf(Len([phone])=10,right([phone],7),[phone]), NewMasterName.AreaCode
= IIf(Len([phone])=10,left([phone],3),"");
0
 

Author Comment

by:DavidNPD
ID: 6923997
I have tried both of these without success, I changed both fields to the text type and when I run the query I get an error that "could not update due to validation rule violations"  Could this be because any of the fields that are empty have a "0"  (zero) in them? I changed both fields back to the Number type and then I get an error that it couldnt update because of a type conversion error. Any ideas?
0
 

Author Comment

by:DavidNPD
ID: 6924021
I have tried both of these without success, I changed both fields to the text type and when I run the query I get an error that "could not update due to validation rule violations"  Could this be because any of the fields that are empty have a "0"  (zero) in them? I changed both fields back to the Number type and then I get an error that it couldnt update because of a type conversion error. Any ideas?
0
 

Author Comment

by:DavidNPD
ID: 6924024
innosys, My mistake, this did work, I thought it hadnt when I saw the errors, Thanks for your help.
hafeezmca, thanks for your reply, your query would have worked as well.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question