Limit characters in a text box

G

Guest

HI,
I have a text box on a form and I want to prevent the user from entering
more than 30 characters. Isn't there a way to prevent data entry after 30
characters are entered?

Thanks,
 
A

Allen Browne

If the text box is bound to a field in a table, you can open the table in
design view, select the field, and change the Field Size property (lower
pane of table design) to 30.

If it is not bound to a field, see:
Unbound text box: limiting entry length
at:
http://allenbrowne.com/ser-34.html
 
G

Guest

Hi Allen,

I did the instruction for the unbound text box and I get the message "Access
can't find the macro ......." for both functions. I create a new module
called "LimitTextInput" and pasted the subs in that module and saved it. Any
Ideas? I'm using Access 2000.

Thanks
 
A

Allen Browne

Set the On KeyPress event for the control to:
[Event Procedure]

Then click the Build button (...) beside the property.
Access will open the code window.

Between the "Private Sub..." and "End Sub" lines, add:
Call LimitKeyPress(Me.City, 40, KeyAscii)

Same kind of process for the On Change property of the text box.
 
G

Guest

I get the error message "can't retrieve the value of this property"

Field is unbound text box

Code for LimitKeyPress and LimitChange are save in a module.

The fields have this events:

Private Sub OldPasscode_Change()
Call LimitChange(Me.OldPasscode, 14)
End Sub

Private Sub OldPasscode_KeyPress(KeyAscii As Integer)
Call LimitKeyPress(Me.OldPasscode, 14, KeyAscii)
End Sub
 

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