CALLING ALL VBA EXPERTS, WHIZZKIDS, PROFESSORS, TUTORS, MASTERS, EXPERIENCED GURUS and LEGENDS!!!! Is it possible to retrict users to enter only 11 numeric digits beginning with 0, with no spaces allowed, as well restrict the user from typing in (dashes) like (-) in the txt box using vba; that also displays an error message: "Invalid Phone number: Re-enter 11 digit Code beginning with 0"? If the user violates against the conditions.
I've enclosed the following code I used for this interesting problem...maybe you have better and effiecient workable code than this. I am a bit of a novice with vba, so if you have sample codes that can perform these requirements without bugs that will be appreciated.
Thanks for your contributions, advise and help I value it very highly
Private Sub Enter_Phone_Number_LostFocus()
'''''Description - Restricts the user from entering no more than 11 digits with spaces and - (dashes) within the text field
'''''Date - 16 April 2011
'''''APW
Dim strText As String, iPos As Integer
strText = TextBox17.Text
If Len(strText) = 11 And Left(strText, 1) = 0 Then
For iPos = 1 To Len(strText)
If IsNumeric(Left(strText, iPos)) Then
'do whatever you do if entry correct
Else
GoTo Error
End If
Next iPos
Else: GoTo Error
Error: MsgBox "Invalid Phone number: Re-enter 11 digit Code beginning with 0"
TextBox17.Activate
End If
strText = vbNullString
Case 48 To 57 'numbers 0 To 11
If Len(TextBox1.Text) = 0 Then
If KeyAscii <> 56 Then KeyAscii = 0 ' must start with 0
End If
End Sub