English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have the tel# 2234657823 for example.
And I need it to look like (223)465-7823.
I have a list of these I need to format in Access.

2006-12-13 03:04:58 · 3 answers · asked by absolutbianca 3 in Computers & Internet Programming & Design

3 answers

I agree with lucee above. But, here is a quick and dirty function to get what you desire :

Function FormatPhoneNumber(ByVal text As String) As String
' Modify a phone-number to the format "XXX-XXXX" or "(XXX)XXX-XXXX".

Dim i As Long

' ignore empty strings
If Len(text) = 0 Then Exit Function

' get rid of dashes and invalid chars
For i = Len(text) To 1 Step -1
If InStr("0123456789", Mid$(text, i, 1)) = 0 Then
text = Left$(text, i - 1) & Mid$(text, i + 1)
End If
Next
' then, re-insert them in the correct position
If Len(text) <= 7 Then
FormatPhoneNumber = Format$(text, "!@@@-@@@@")
Else
FormatPhoneNumber = Format$(text, "!(@@@)@@@-@@@@")
End If
End Function

Just drop that in a public module, and insert the function() into your update query.

Good luck!

2006-12-13 03:52:48 · answer #1 · answered by Special Ed 5 · 0 0

You have a separate field for area code, prefix (465) and the last four numbers. That way, you can sort by area code or prefix.

2006-12-13 03:16:41 · answer #2 · answered by Anonymous · 0 0

Set up an Input Mask.

2006-12-13 03:08:29 · answer #3 · answered by Yoi_55 7 · 0 0

fedest.com, questions and answers