Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

limit the length of a textbox for unbound form 3

Status
Not open for further replies.

mrMika

Programmer
Jun 17, 2003
34
CA
How do I limit the length data going into a textbox for an unbound form. Am I stuck using a input mask?
 
You may play with the Len function in the Change event procedure of the textbox.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi!

You can use the following code in the Change event procedure:

If Len(YourTextBox.Text) > YourLimit Then
Call MsgBox("You cannot add any more characters")
YourTextBox.Text = Left(YourTextBox.Text, YourLimit)
End If

If you do something like this, make sure the user knows about the limit and I would add a lable at the top of the text box that I use the Change event procedure to update with the current length of the text box.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Jebry,

I thought that this would work but it does not. On the change event it does look at the field length that was originally there but the length will not change from the originall. for Example: the field may have had the word "test" in it orignally which has a length of 4. Change this to "testy" and the variable that it looks at for the length has not changed (still test) and still has a length of 4. Any ideas?
 
Hi!

Yes, note that I used the .Text which does change as the user types into the text box. The .Value or just using the name of the text box will not change until the user exits the text box.

hth


Jeff Bridgham
bridgham@purdue.edu
 
thanks for the tip about the .Text. i learnt something new today!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top