Limit number of chars

L

Luis

Hello.
I have an unbound text box for users to input data. I want to limit the
input string to 50 chars. How do i do this on an unbound control?
I also like to create a label that shows the string length as the user types.

Thanks.

Luis
 
J

JackP

You could do this by using an input mask.

For example, an input mask of CCCCCCCCCC would allow any characters or
spaces up to a maximum of 10 in length to be included (but no minimum).
Increase the number of C's to increase the length allowed. (You can do this
more neatly - look up regular expressions)

Alternatively, you could have an after update event in your field which did
something like

if len(Me!MyField) > 50 then
me!MyField = left(Me!MyField,50)
Msgbox "Your text has been truncated - only 50 characters allowed"
end if
 
F

fredg

Hello.
I have an unbound text box for users to input data. I want to limit the
input string to 50 chars. How do i do this on an unbound control?
I also like to create a label that shows the string length as the user types.

Thanks.

Luis

Here is one method.

You can set the unbound control's Validation Rule property to:
Len([ThisControlName])<=50
As Validation Text write whatever message you want.

If you also wish to have a label count the number of characters as
they are entered, add another unbound control.
Name it CountControl.
Set the Change event of the previous control to:
[CountControl] = Len(Me![ThiscontrolName].Text)
 
M

Marshall Barton

Luis said:
I have an unbound text box for users to input data. I want to limit the
input string to 50 chars. How do i do this on an unbound control?
I also like to create a label that shows the string length as the user types.


Use the text box's Change event:

If Len(Me.textbox.Text) > 50 Then
Beep
Me.textbox.Text = Left(Me.textbox.Text, 5)
End If
Me.textbox.Controls(0).Caption = Len(Me.textbox.Text)
 

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