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
JackP - 13 Jul 2005 17:29 GMT
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
fredg - 13 Jul 2005 18:22 GMT
> Hello.
> I have an unbound text box for users to input data. I want to limit the
[quoted text clipped - 4 lines]
>
> 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)

Signature
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Marshall Barton - 13 Jul 2005 18:35 GMT
>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)

Signature
Marsh
MVP [MS Access]