473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

telephone formatting

I need to reformat a cell that contains telephone numbers to a format of
(###) ###-#### but the original cells have various symbols such as / . - \
() etc is there a way to replace all of these symbols and then reformat
accordingly?

Examples of what needs to be corrected:
555-555-1212
555/555-1212
(555)5551212
555.555.1212
555\555\1212

I want them to end up all looking like (555) 555-1212 in my query results.

Thanks,
P.
Jun 27 '08 #1
4 1589
You could put these functions into a Standard Module:

Dim RegularExpression As Object

Private Function InitializeRegularExpression()
Set RegularExpression = CreateObject("VBScript.RegExp")
With RegularExpression
.Global = True
.IgnoreCase = True
End With
End Function

Public Function NumericOnly$(ByVal vInput As String)
If RegularExpression Is Nothing Then InitializeRegularExpression
With RegularExpression
.Pattern = "[^0-9]"
NumericOnly = .Replace(vInput, "")
End With
End Function

Public Function FormattedTelephoneNumber$(ByVal vInput)
FormattedTelephoneNumber = Format(NumericOnly(vInput), "\(000\)\
000\-0000")
End Function

You could use them as in:
"SELECT FormattedTelephoneNumber([Business Phone]) FROM Customers"

On May 17, 8:44*am, "Pat_RI" <pat2469...@zzcox.netwrote:
I need to reformat a cell that contains telephone numbers to a format of
(###) ###-#### but the original cells have various symbols such as / . - \
() etc is there a way to replace all of these symbols and then reformat
accordingly?

Examples of what needs to be corrected:
555-555-1212
555/555-1212
(555)5551212
555.555.1212
555\555\1212

I want them to end up all looking like (555) 555-1212 in my query results.

Thanks,
P.
Jun 27 '08 #2
Hi

I assume the slashes, parenthesis, dashes, etc are actually in the text of
the field and that its not so much the
format that you want to change but the but the content.

Look at the replace function in the Access VBA help function.

Create an update query and using the replace function Get rid of all of the
characters other than numerals.

Update to: Replace(TelNo,"-","") 'This gets rid of all the dashes in the
records that have them.
Do the same for the other characters.

You'll be left with 10 digit numeric strings.

If you want to include the actual characters in your data you can do another
update query to put them in.
You can then put in the characters that you want where you want them with
something like:

Update to: "(" & left(TelNo,3) & ") " & mid(TelNo)4,4) & "-" &
right(TelNo,4)
That would yield (781) 678-9807.

Regards
Kevin

"Pat_RI" <pa********@zzcox.netwrote in message
news:xq*****************@newsfe18.lga...
>I need to reformat a cell that contains telephone numbers to a format of
(###) ###-#### but the original cells have various symbols such as / . - \
() etc is there a way to replace all of these symbols and then reformat
accordingly?

Examples of what needs to be corrected:
555-555-1212
555/555-1212
(555)5551212
555.555.1212
555\555\1212

I want them to end up all looking like (555) 555-1212 in my query results.

Thanks,
P.

Jun 27 '08 #3
On Sat, 17 May 2008 08:44:10 -0400, Pat_RI wrote:
I need to reformat a cell that contains telephone numbers to a format of
(###) ###-#### but the original cells have various symbols such as / . - \
() etc is there a way to replace all of these symbols and then reformat
accordingly?

Examples of what needs to be corrected:
555-555-1212
555/555-1212
(555)5551212
555.555.1212
555\555\1212

I want them to end up all looking like (555) 555-1212 in my query results.

Thanks,
P.
Directly in a query (all on one line).
NewPhoneNumbers:Format(Replace(Replace(Replace(Rep lace(Replace(Replace([OldPhoneNumbers],"/",""),".",""),"\",""),"-",""),"(",""),")",""),"(@@@)
@@@-@@@@")
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Jun 27 '08 #4
Hi -

For A97 dinosaurs (no built-in Replace() function):

? format(fSaveNumer2("( 800 -555/1212"), "(@@@) @@@-@@@@")
(800) 555-1212

with fSaveNumer2() being:

Public Function fSaveNumer2(pStr As String) As String
'purpose: Removes all non-numeric characters from a
' string.
'coded by: raskew
'calls: IsNumeric()
'Input: ? fSaveNumer2("( 800)--555/1212")
'Returns: 8005551212

Dim strHold As String
Dim strKeep As String
Dim intLen As Integer
Dim n As Integer

strHold = Trim(pStr)
intLen = Len(strHold)
For n = 1 To intLen
If IsNumeric(Mid(strHold, n, 1)) Then
strKeep = strKeep & Mid(strHold, n, 1)
End If
Next

fSaveNumer2 = strKeep

End Function

fredg wrote:
>I need to reformat a cell that contains telephone numbers to a format of
(###) ###-#### but the original cells have various symbols such as / . - \
[quoted text clipped - 12 lines]
>Thanks,
P.

Directly in a query (all on one line).
NewPhoneNumbers:Format(Replace(Replace(Replace(Re place(Replace(Replace([OldPhoneNumbers],"/",""),".",""),"\",""),"-",""),"(",""),")",""),"(@@@)
@@@-@@@@")
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200805/1

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ashish | last post by:
I wanted to make a Java application which would dial a telephone number using the modem. When the person on the other end lifts up the telephone (answers the phone), the application should start...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
4
by: Iftikhar Hussain | last post by:
Hello Everyone Nice to be back here, well all u guys have helped in past & now I would like a favor again. first what i want to develop is as follows: An application for rescue station, where...
1
by: Robert Johnson | last post by:
Hi all. I need to format my text box's and combo box's with Telephone (###) ###-#### and Postal Code #####-#### or other custom formating, how do I do this? I tried to go into Properties,...
10
by: Nkhosinathie | last post by:
This isn't a homework,i want to improve my skills in programming and apply my understanding to pinters. i'm developing a program that will print telephone numbers randomly for a city for...
3
by: Smythe32 | last post by:
Hi, I am in need of some assistance. I have a table with the following: Tel_St_Range Tel_End_Range Customer Name 6075551200 6075551300 Tom Smith I would like to know how to...
0
by: tlontz | last post by:
I am trying to retrieve the telephone_number from active directory using the following script: Dim search As New DirectorySearcher("") search.Filter =...
5
by: rikigr4 | last post by:
Hi All, I am looking for code written in .NET that provides connection between application and telephone. So that - the telephone will return a code according to input code that it get's from the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.