Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Split 10 digit phone numbers into 2 fields

Posted on 2002-04-06
5
Medium Priority
?
336 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 200 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

604 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