Article ID: 180816
Article Last Modified on 1/22/2007
tblPhoneNumbers
--------------------------
Field Name: OriginalNumber
Data Type: Text
Field Name: NewNumber
Data Type: Text
OriginalNumber NewNumber
-------------- ---------
(111) 123-4567
( ) 345-6789
NOTE: No values are entered in the NewNumber field.
Function ConvertPhone(phone As String)
Dim PhoneLen As Integer
On error Goto ConvertPhone_err
' Determine if a valid number exists. If not, exit function.
If Len(phone) = 7 Or Len(phone) = 10 Then
PhoneLen = Len(phone)
Else
Exit Function
End If
' Format number and return value to function name.
Select Case PhoneLen
Case 7
ConvertPhone = "( ) " & Left(phone, 3) & _
"-" & Right(phone, 4)
Case 10
ConvertPhone = "(" & Left(phone, 3) & ") " _
& Mid(phone, 4, 3) & _
"-" & Right(phone, 4)
End Select
ConvertPhone_exit:
Exit Function
ConvertPhone_err:
' Use the following line if you are
' running Microsoft Access 7.0 or 97.
MsgBox Cstr(Err) & " " & Err.Description
' Use the following line if you are
' running Microsoft Access 2.0.
' MsgBox CStr(Error) & " " & Error(Err)
Resume ConvertPhone_exit
End Function
ConvertPhone([OriginalNumber])
NewPhone: ConvertPhone([OriginalNumber])
Additional query words: inf phone number mail merge Word
Keywords: kbhowto kbprogramming KB180816