How do I set the max characters on a textbox?

G

Guest

I want to make a textbox that will not allow more than 10 characters. How do
I set the max characters or limit to 10 characters? Thanks.
 
B

Brian

lanem said:
I want to make a textbox that will not allow more than 10 characters. How do
I set the max characters or limit to 10 characters? Thanks.

If it's a bound textbox, the easiest thing would be to set the field size to
10 in the table.
 
G

Guest

Sorry if this is too basic, but I'm new to Access programming.
What's the difference in bound and unbound?
Also, the table field size is set to 10, but it doesn't give the user an
error message if they go over.
 
M

Mark

Brian is referring to a control (in this case the textbox) on a form or
report. If it's a bound control, it is assigned to a field in the table on
which the form is based and allows you to see and edit the values in the
table. If it's an unbound control, then it is not assigned to anything and
is usually used to display various bits of information that the programmer
wants to show the user. If your textbox is bound to the 10-character field,
it will just stop accepting keystrokes after the tenth character is entered.
 
M

Marshall Barton

lanem said:
I want to make a textbox that will not allow more than 10 characters. How do
I set the max characters or limit to 10 characters?


If you don't want to set the field length to 10, then you
could set the text box's Validation Rule to:
Len([Text0])<=10
and set the Validataion Text to a meaningful message.

If you want to check the length as the user is typing, then
use the text box's Change event:

If Len(Text0.Text) > 10 Then
Beep
Text0.Text = Left(Text0.Text, 10)
Text0.SelStart = 10
End If
 
G

Guest

Thanks. This is exactly what I was looking for.

Marshall Barton said:
lanem said:
I want to make a textbox that will not allow more than 10 characters. How do
I set the max characters or limit to 10 characters?


If you don't want to set the field length to 10, then you
could set the text box's Validation Rule to:
Len([Text0])<=10
and set the Validataion Text to a meaningful message.

If you want to check the length as the user is typing, then
use the text box's Change event:

If Len(Text0.Text) > 10 Then
Beep
Text0.Text = Left(Text0.Text, 10)
Text0.SelStart = 10
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top