-
Situation: The program runs and the user is instructed to enter his or her name in a textbox(txtNAME)and then hit ok (cmdOK).
What code would I put in for cmdOK so that if 10 or more characters are entered in txtNAME a message box saying "Your name is too long" appears?
If you can help me out I would appreciate it.
Thanks in advance
Beres
[email protected]
-
<?>
'send a msgbox if maxlength is reached...
Private Sub Text1_KeyPress(KeyAscii As Integer)
' dispose of the control keys
If KeyAscii < 32 Then Exit Sub
'set the max length of textbox
text1.maxlength = 10
If Len(Text1.Text) = 10 Then
MsgBox "Sorry, 10 characters is all you get."
End If
End Sub
-
Two ways of doing this:
Either set the MaxLength property to 10.
Code:
Private Sub Form_Load()
Text1.MaxLength = 10
End Sub
Or:
Code:
Private Sub Text1_Change()
If Len(Text1.Text) = 10 Then
Text1.Locked = True
End If
End Sub