A user control is used to check the data being entered in a text control for alphabet characters and throws an error when other characters are entered in it.
Private Sub Text1_LostFocus()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim str As String
str = Trim(Text1.Text)
k = 0
l = 0
For i = 1 To Len(str)
For j = 65 To 122
If Mid(str, i, 1) = Chr(j) Then
k = k + 1
End If
Next j
If Mid(str, i, 1) = Chr(32) Then
l = l + 1
End If
Next i
'MsgBox "K: " & k
'MsgBox Len(str)
'MsgBox str
k = k + l
If k < Len(str) Then
MsgBox "Please Enter Valid Characters"
End If
End Sub
Private Sub Text1_LostFocus()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim str As String
str = Trim(Text1.Text)
k = 0
l = 0
For i = 1 To Len(str)
For j = 65 To 122
If Mid(str, i, 1) = Chr(j) Then
k = k + 1
End If
Next j
If Mid(str, i, 1) = Chr(32) Then
l = l + 1
End If
Next i
'MsgBox "K: " & k
'MsgBox Len(str)
'MsgBox str
k = k + l
If k < Len(str) Then
MsgBox "Please Enter Valid Characters"
End If
End Sub
No comments:
Post a Comment