Limiting a TextBox to 127 characters

J

Jeff

Hello,

What I am looking for is a way to limit a user to having more than 127
characters in a Text Box. I know the simple way is to have an Input Mask.
But I dont want to use the Input Mask Property, I can explain why if needed.

So one way I know you can is in the KeyDown Event...

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Len(txtNotes.Text) > 126 And Then KeyCode = 0
End Sub

This works if the user tries to TYPE more than 127 characters. But it does
not help if the Users COPIES and PASTEs text into the Field. So for example
if there are 100 characters in there & they Copy some large text from
somewhere else & then Right click & Paste into this one it will take it. How
can I prevent this from happening ? But want to allow to Paste if total is
less than 127 characters.

I know I can also use the BeforeUpdate & AfterUpdate Events to trim down the
large amount of Text after the fact, but what I prefer is to just not allow
it from the begining.

So some way to prevent users from Pasting more than 127 Characters.

Any help would be greatly appreciated.

Thank You,
Jeff
 
J

Jeff

Ken thank you, but as I mentioned the BeforeUpdate & AfterUdate Events are
not triggered until the user moves the focus away from the control.

I want to prevent before this happens... any way ?

Thank you,
Jeff
 
J

Jeff

Sorry I figured it out, can use the CHANGE EVENT as that is triggered & then
I just used =Left(...,127)

Thank you
 
R

Rick Brandt

Jeff said:
Hello,

What I am looking for is a way to limit a user to having more than 127
characters in a Text Box. I know the simple way is to have an Input Mask.
But I dont want to use the Input Mask Property, I can explain why if needed.

Any reason you don't just use a Text DataType in the table with the length set
to 127?
 

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