austin350s10
Active Member
- Joined
- Jul 30, 2010
- Messages
- 321
Does anyone know how to use vba to format a phone number to the correct format? For some reason when a user enters a phone number with this format: (###)###-#### my script will not change the value to the correct format of: (###) ###-####. The only format difference is the space between the area code and the start of the phone number. The code below tests as true and executes the 2nd line of code but its almost as if the format function does not recognize the space. Do I need to use a special character or something to represent a space when formatting? Or am i doing this completely the wrong way?
not working:
working:
not working:
Code:
If Len(me.txtPhone.Value) = 13 And me.txtPhone.Text Like "(###)###-####" Then
me.txtPhone.Value = Format(me.txtPhone.Text, "(###) ###-####")
End If
working:
Code:
If Len(me.txtPhone.Value) = 10 And me.txtPhone.Text Like "##########" Then
me.txtPhone.Value = Format(me.txtPhone.Text, "(###) ###-####")
End If