PDA

View Full Version : MaxLength for Textbox



mferrisi
11-29-2007, 10:16 AM
I created a textbox via the method copied below, and everything worked fine until I tried to limit the number of characters that the user could add
(at least that is what I was trying to do with the tb2.Maxlength = 1 line).

Set tb2 = ActiveWorkbook.Worksheets(1).Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, _
Left:=383, Top:=38 + (x - 1) * 12.75, Width:=12.5, Height:=12.75)
tb2.TextFrame.Characters.Font.Size = 8
tb2.TextFrame.Characters.Font.FontStyle = "Times New Roman"
tb2.MaxLength = 1
tb2.TextFrame.Characters.Text = Right(x, 1)
tb2.Name = "tbx" & x

Thank you for your help,

Matt

figment
11-29-2007, 10:30 AM
what error did you get?

mferrisi
11-29-2007, 12:11 PM
'Object doesn't support this property or method

lucas
11-29-2007, 12:13 PM
That's just the beginning of the problems you will run into creating objects on the fly. Just hide them.

mferrisi
11-29-2007, 12:45 PM
Does that mean there isn't a way?

lucas
11-29-2007, 01:28 PM
No it just begs the question....why create objects on the fly and deal with the problems it brings when you don't have to.

figment
11-29-2007, 01:31 PM
No it doesn’t, it just means that the bugs will be much larger then normal. Tread carefully for that way leads to dragons

(sorry lucas your post wasn't there when i loaded the page)

lucas
11-29-2007, 01:38 PM
No problem figment.....

It would be different if there were no alternative......glad we agree.

mferrisi
11-29-2007, 01:45 PM
The user is setting the parameters-- including the number and type. All other buttons, boxes, and windows can be created with the 'addformcontrol' which makes everything much easier. However, if they create a textbox, I have to use the method above. As time is an issue, I'd rather not create 400 form objoects and then code around them.

Thank you for your help,

lucas
11-29-2007, 01:52 PM
Sorry Matt,
I'm not trying to shoot you down. Have you gotten to the point of coding these items yet? I mean to do something besides create them......

All other buttons, boxes, and windows can be created with the 'addformcontrol' which makes everything much easier.

Let us know how this goes for you.

figment
11-29-2007, 02:12 PM
where are you making these objects? for the MaxLenght property is restricted to forms only. and it takes a long as an input, so try storing the number 1 into a long varable then seting the property = to the varable instead.