How to validate a textbox on Lost Focus event so that only alphabetic characers are possible?of eq if the field is Name :ehh:
Printable View
How to validate a textbox on Lost Focus event so that only alphabetic characers are possible?of eq if the field is Name :ehh:
U can use this code in the keypress event
Copy the following code in the keypress event
dim strvalid as string
strvalid="abcdedfghijkilmnopqrstuvwxyzABCEDEFGHIJKILMNOPQRSTUVWXYZ"
If InStr(strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
Hopes it helps u
First you could catch the key pressed in the keypress event and if its a number then cancel it but that still doesnt stop them pasting a number in so try looping through the textbox in the validate event
VB Code:
Private Sub Text1_Validate(Cancel As Boolean) Dim i As Integer For i = 1 To Len(Text1.Text) If IsNumeric(Mid$(Text1.Text, i, 1)) Then MsgBox "No Numbers Please" Cancel = True Exit For End If Next i End Sub
casey.
Thanx,that was helpful, but how to ignore values like ';./,]{}_+| and have an error message come up if these values are input?
Help,Anyone,please...???
Check each Ascii character.
VB Code:
Dim i As Integer For i = 1 To Len(Text1.Text) Select Case Asc(Mid$(Text1.Text, i, 1)) Case 65 To 90 'A - Z Case 97 To 122 'a - z Case Else MsgBox "Invalid Character " & Mid$(Text1.Text, i, 1) Cancel = True Exit For End Select Next
Wow,thank you soo much!!!!!