Limited a memo field to 1000 characters

access my brain

New member
Local time
Today, 21:07
Joined
Aug 21, 2003
Messages
8
Is there a way to limit the character size for a Memo box?.

I need to get the Memo box to stop at 1000 characters when the user is typing and just stop typing like a text box, which limits you to 255 characters.

Can anyone post some example code for this?!?

thanks!
 
As far as I can tell you can't stop it the way you'd like due to the Key events: KeyDown, KeyPress, and KeyUp.

It seems that after the last event fired (KeyUp) the code is run but the next letter is inserted after the event is complete.
 
Try this code in the control to be controlled...

Code:
Private Sub YourControl_KeyDown
If Len(me.YourControl.Text) => 1000 and Keycode <> vbkeydelete and keycode <> vbkeyback Then
KeyCode = 0
End If

This is something that would work well as a custom function / Sub so that you could use it for a selection of controls.
 
Fizzio, it works, except now the user can't edit anything inside the text box. :D
 
Probably best to rewrite the code to check the SelStart is not at the allowed Len.
 
dcx693 said:
Fizzio, it works, except now the user can't edit anything inside the text box. :D
So what;)

Cheers Mile-O:o
 
Hey guys, I was just leafing though my Access 2000 Developers Handbook and chanced across a solution to this exact problem. It involves using a Windows API function. It's a bit too long to type out here (and I'm sure some copyright issues are involved :D ), so I'll just point you to it. It's page 474 under "Using SendMessage to Limit Input Characters".
 

Users who are viewing this thread

Back
Top Bottom