Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

phone number field, convert to set format?

Status
Not open for further replies.

jimmperry

Programmer
Jan 31, 2003
8
US
I have a field with phone numbers in it. Howerver, some numbers are 4 digits(xxxx), some 7 (xxxxxxx) and others 10 (xxxxxxxxxx). I would like to put parenthesis around the numbers that have area codes, and dashes (-) between the other goups of numbers (I.E. xxx-xxxx). Any ideas?
 
Use an If then state, then test the length of the string length({string}). If the string legth is only 7 digits you would use Mid({string},1,3)+"-"+mid({string,4,7) and if the test shows 10 digits you would do the same thing but just add the "(" first instead of the "-" with the mid instructions as you go along. and so on for the 4 digits too Mark
Email: markanas333@hotmail.com
 
Here is pretty much the same method, but without using the mid function.

stringvar phone:={phone.number.field};
// use if your field is a string
stringvar phone:=totext({phone.number.field},0,"");
//use this if your field is a number and not a string


if length({phone})=10 then "("+phone [1 to 3]+")"+ phone[4 to 6]+"-"+phone[7 to 10] else
if length({phone})=7 then phone[1 to 3]+"-"+phone[4 to 7] else
phone Mike
If you're not part of the solution, you're part of the precipitate.
 
use the picture() function to make this very easy.

picture({PhoneNoField},"(XXX) XXX-XXXX") will return the field exactly the way you would want a 10 digit phone number to appear. You can use the if-then statemtnt in conjuntion with this to get exactly what you want. Software Sales, Training and Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
This was great guys, thanks for the fast response. I got it and Im outa here!
 
I can't get past the stringvar. The field is a number.

stringvar ssn:=totext({MASTER_NAMES.SSN},0,"");

I am getting an error stating

"The formula must result in a boolean"

 
What is it that you're trying to do and where are you placing this formula?

The syntax looks fine, so I'm assuming that you're placing this in the wrong place.

Create a new formula and put it in there:

Insert->Field Object->Right click Formula Fields->New

-k
 
Hmmmm.... You're right. It worked.

Can't remember where I was trying to do this but I think I got into the Formula Editor by way of Format Field and thought I was creating a formula.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top