|
-
Jun 1st, 2008, 05:53 AM
#1
Thread Starter
Addicted Member
[RESOLVED] validation of a text box
hi i have a text box which does not have to exceed 10 characters code below:
Code:
If Len(text1.Text) > 10 Then
MsgBox "text box 1 length out of range"
End If
so when i type in some text and EXCEED the length of the text box (10) it gives me an message box. which is what i want. BUT after the message box has appeared i can click ok and happily type more characters in. so i was wondering what code i will need so there for more data cannot be entered and if it is then an error message appears?
thanks in advance
-
Jun 1st, 2008, 06:11 AM
#2
Frenzied Member
Re: validation of a text box
try like this
Code:
Private Sub Text1_Validate(Cancel As Boolean)
If Len(Text1.Text) > 10 Then
MsgBox "text box 1 length out of range"
Cancel = True
End If
End Sub
EDIT:
Also, if use set MaxLength property to 10 for the text box, this could be done, Only thing you wont get the message box.
-
Jun 1st, 2008, 06:21 AM
#3
Thread Starter
Addicted Member
Re: validation of a text box
it does not work how i want it to work.
at the moment i have a text box which has a length of 10 characters, and if i exceed the number of characters, then an error message appears but after clicking ok i can add more characters i have tried to use max length but i want the text box NOT to be able to accept more characters and not to give a system beep, but an error message.
thanks for the quick reply.
-
Jun 1st, 2008, 08:10 AM
#4
New Member
Re: validation of a text box
try this:
Code:
Private Sub Text1_LostFocus()
If Len(Text1) > 10 Then
MsgBox "larger than 10, please enter again", vbExclamation
Text1.SetFocus
End If
End Sub
if you leave this text box, an error msg will be popped up. hope this helps
-
Jun 1st, 2008, 09:30 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|