Limit character entry

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

Guest

Is there any way to limit the number of characters entered into a form field
based on another field's value? I have a form that normally accepts 15
characters, but in certain circumstances I would like to only accept 4. How
could I generate a message box if the user tries to enter a fifth character
when another field on the form has a certain value?

This text field is for a date, but I have it set as a text field so that the
user can enter either a year only, a year and a month, or a year, month &
day. It is also necessary to use the term "about" after the date
occasionally. In certain circumstances I want it to be a year only. Is this
possible?

Thanks for all the help you've given me in the past!
 
Try using the KeyPress Event of the TextBox and check the length of the Text
Property of the TextBox.

Check Access VB Help on KeyPress Event (of a TextBox).
 
Thank you for your quick reponse. I think, however, I'm going to need a
little more information. Forgive me, I'm new at this!

The KeyPress Event seems right to me, though I'm not sure what you mean by
the Text Length property - it's 15 in the underlying table - is there a
different setting on the form itself? Also, the VB help for the KeyPress
event instructs on the disallowing of ancsii keys. I don't see how that
really applies - I just want to disallow anything over 4 characters.

If possible, I think I need something a little more specific. Thanks!
 
Try the following , I am not sure of the actual coding.

Use the on change event

then use the .sellength property to count the number of characters as the
user enter data in the field.
If the length exceeds your maximum then display as message.

I used the above concept where the extra characters in the field were
trimmed so that only the maximum characters were displayed.

I will post the actual code in the newsgroup later tomorrow when I go to
work at have a look at the actual coding.
 
Back
Top