I have a field in a form that i want the user to use for entering telephone numbers. I want the data entered to have no spaces in it. Is there a special format or rule i could use to eliminate spaces after the user has entered the data?
an input mask would not do what i want - i want the data to be spaceless after input - so a format would be better - and i need someones help to do this.
To remove spaces from either end of a string, and I'm guessing the phone number is a string, you can use the Trim() function.
If there are spaces within the string then here's a function to get round that. Put the function in a module.
Code:
Public Function RemoveSpaces(ByVal strText As String) As String
On Error Goto Err_RemoveSpaces
Dim intCounter As Integer
For intCounter = 1 To Len(strText)
If Mid(strText, intCounter, 1) <> " " Then
RemoveSpaces = RemoveSpaces & Mid(strText, intCounter, 1)
End If
Next intCounter
Exit_RemoveSpaces:
Exit Function
Err_RemoveSpaces:
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_RemoveSpaces
End Function