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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format phone number xxx-xxx-xxxx to (xxx) xxx-xxxx 1

Status
Not open for further replies.

LisaRR

Technical User
May 2, 2003
31
US
I am trying to format a string phone number field from the current xxx-xxx-xxxx format to (xxx) xxx-xxxx.

I reviewed the posts in threat 767-608674 but I am not able to get the suggested formulas to work. This is what I have now:

stringvar fmtPhone;

replace(replace(replace(replace({TABLE.PHONE},"(", ""), ")", ""), "-", ""), " ", "");
"(" & left(fmtPhone, 3) & ") " & mid(fmtPhone, 4, 3) & "-" & mid(fmtPhone, 7, 4)

The result returns only the formatting, not the formatted field: Example:
() -

I also tried this:
StringVar fmtPhone;
fmtPhone = Replace( {TABLE.PHONE}, "(", "" );
fmtPhone = Replace( fmtPhone, ")", "" );
fmtPhone = Replace( fmtPhone, "-", "" );
fmtPhone = Replace( fmtPhone, " ", "" );

"(" & left(fmtPhone, 3) & ") " & mid(fmtPhone, 4, 3) & "-" & mid(fmtPhone, 7, 4) ;

with the same result.

anyone have any feedback for how to make these formulas work? Thanks!
 
i think this might do it for you:
{@phone}
"(" & LEFT({table.phone},3) & ")" & RIGHT({table.phone),8)


my standard disclaimer plus a little extra applies today..... i do not have crystal in front of me so apologize for any errors or typos.
I am also a bit sleep deprived and there is not enough coffee in the building today to get me up to speed, so if i misunderstood your issue, additional apologies.
 
if you may potentially have nulls in the data, add this line
IF is null({table.phone) then "" else
 
That did it - you understood perfectly. Thanks so much!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top