limiting number of characters in vba

lala

Registered User.
Local time
Today, 15:52
Joined
Mar 20, 2002
Messages
741
hi, how do i limit the number of characters in a field in vba. limiting it in a table doesn't work for me because the same field has to accept different number of characters depending on a value in another field


so for example, if the value in that field is 0 then the field should accept 40 chars, if it's 1 then accept 150 chars.


thank you!!
 
You can use the Len() function to determine the number of charters in a field. So you could test the Len() in the Field's On Change event and disable the field once number of charters reaches the desired limit.
 
allen browne has a recipe for that, whcih also takes care of sneaky users pasting stuff into a textbox (and surely, you refer to a textbox right? No direct access to a field in a table should be allowed.

. http://allenbrowne.com/ser-34.html
 
You can use the Len() function to determine the number of charters in a field. So you could test the Len() in the Field's On Change event and disable the field once number of charters reaches the desired limit.

thank you so much, i was trying on dirty, key down. i don't know the events that well. i tried reading the help file and don't get some of them still))))


so thank you and thank you spikepl too)))))
 
You can use the Len() function to determine the number of charters in a field. So you could test the Len() in the Field's On Change event and disable the field once number of charters reaches the desired limit.

on change didn't work for me but the example from AllenBrowne did

i probably did the onchange wrong
but i got it to work so thank you, both of you, very much!!!!!!!!!!
 
...

i probably did the onchange wrong
but i got it to work so thank you, both of you, very much!!!!!!!!!!

In most cases the data has not been committed at the time the On Change event fires so you need to use;
Code:
Len(Me.YourField.Text)
 
I knew it was me, thank you again!!
 
In most cases the data has not been committed at the time the On Change event fires so you need to use;
Code:
Len(Me.YourField.Text)
... and you (i.e. lala) was probably using .Value instead of .Text
 

Users who are viewing this thread

Back
Top Bottom