PDA

View Full Version : Solved: Limit character input in a textbox



jammer6_9
06-12-2010, 06:42 AM
I was looking for the text box properties if i can limit the input to 200 characters only but there was no options? can we do this by giving a code?

GTO
06-12-2010, 07:00 AM
Private Sub UserForm_Initialize()
Me.TextBox1.MaxLength = 200
End Sub

Tinbendr
06-12-2010, 07:33 AM
IF you want to give the user a little feedback, then
Private Sub TextBox1_Change()
If TextBox1.TextLength > 10 Then
MsgBox "Too long"
TextBox1.Text = Left(TextBox1.Text, TextBox1.TextLength - 1)
End If
End SubLeave the Maxlength at 0 and let this sub manage it.

jammer6_9
06-13-2010, 12:16 AM
Perfect... Thanks:thumb

JJF
09-28-2014, 08:59 AM
Hi there. I get an "object required" error message if I try running that code. Has anyone else had the same issue?

GTO
09-30-2014, 02:00 AM
Hi there. I get an "object required" error message if I try running that code. Has anyone else had the same issue?

Hi JJF and welcome to vbax!

I am sure you will be happy you joined, as there are a lot of good folks here who will go out of their way to help you. As I have responded to many (new members) before, there is just the greatest amount of patience and helpfulness here.

Anyways, as to your issue - I would suggest you start your own thread. Certainly include a link to this one for your initial question, but a new thread not only helps you, but others searching later.

Now to your question - what code errors? Presuming the TextBox is named TextBox1, both Tinbendr's code and mine seems to run, so please show us exactly how you wrote the code that fails.

Hope to help,

Mark