Solved

Split 10 digit phone numbers into 2 fields

Posted on 2002-04-06
5
312 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

726 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