Limit number of chars

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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)
 
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)
 
Back
Top