By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

How to check the max length

chandru8
100+
P: 145
Hi experts
In my project ill having many textboxes , for that i have to check the maxlength for exch textbox , the length should be equal to maxlength mentioned

how can we check this in general

i have written code in lost focus for each text box is there any better idea

and this code is possible

If txtAccountno.MaxLength = True Then
'its not working
Else

MsgBox ""

End If
thanks
Nov 28 '07 #1
Share this Question
Share on Google+
6 Replies


Expert 5K+
P: 8,434
You could do a loop through the Me.Controls collection, check for type of textbox (or check the name) and then test the length against MaxLength.

(Note, this applies to VB6. I don't know how you access the controls collection in later versions.)
Nov 28 '07 #2

chandru8
100+
P: 145
thanks killer
is it possible to assign the tabindex for select text box if some other category choosen mean for that text box the tab index should be set from the begining


thank you so much
Nov 28 '07 #3

Expert 5K+
P: 8,434
thanks killer
is it possible to assign the tabindex for select text box if some other category choosen mean for that text box the tab index should be set from the begining
I don't know. Try it, and see what happens.
Nov 28 '07 #4

P: 63
Here's an example of an if statement which checks the length of a credit card number.

If Len(txtCreditCard.Text) < 16 Then

MsgBox "The Credit Card Number should consist of 16 numeric characters", vbExclamation, "Note"

End If
Nov 28 '07 #5

Ali Rizwan
100+
P: 927
Use this code to restrict the textbox input size.
Expand|Select|Wrap|Line Numbers
  1.  
  2. if len(text1)>6 then
  3. msgbox "More than 6 characters are not allowed"
  4. text1.text=""
  5. text1.setfocus
  6. end if
no when ever the user input more than 6 digits or characters a msg box appers and text1 will empty and get focused

i think this will help you.

GOODLUCK
ALI
Nov 28 '07 #6

9815402440
100+
P: 180
hi
set the MaxLength property of text box in Properties window at design time.
user wont be able to type more than MaxLength characters.

regards
manpreet singh dhillon hoshiarpur
Nov 28 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.