Formatting Phone Numbers In Crystal Reports

I would think that formatting a phone number would be a pretty standard task in Crystal Reports so I’m not sure why this bit of information was so hard to find on the Internets. But anyway, for my own reference and maybe to help out someone else, here is how you do it. For the sake of version differences note that I am using Crystal Reports Version 10.

To format a raw data phone number:

Right click on Formula Fields option in the Field Explorer

Select Add New

Create a name for the Formula Field. I simply named mine Phone Number because there is only one phone number listed in the report, but as I better practice the name should have been more descriptive. Something like School Contact Phone Number would have been better.

Select User Editor

In the Formula Editor, paste the following code substituting table.field for your table and field.


/*

VB Syntax, Format Phone Number

*/
Picture (CStr ({table.field}), "(xxx) xxx-xxxx")

Save and close the Formula Editor

All that is left to do is drag the Phone Number Formula Field into your report in instead of the actual phone number field itself.

The Formula Fields Editor is a very powerful utility. While I’m on the topic, I’ve also found a great formula to page your reports in the same style we are all used to seeing in Microsoft Word.


/*

Paging Numbers Formula

*/
NumberVar startNum := 0;
"Page " + ToText((PageNumber + startNum), 0) +
" of " + ToText((TotalPageCount + startNum), 0)

Leave a Reply