Consulting

Results 1 to 11 of 11

Thread: MaxLength for Textbox

  1. #1

    MaxLength for Textbox

    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).

    [vba]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[/vba]

    Thank you for your help,

    Matt

  2. #2
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    what error did you get?

  3. #3
    'Object doesn't support this property or method

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    That's just the beginning of the problems you will run into creating objects on the fly. Just hide them.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Does that mean there isn't a way?

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    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)

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    No problem figment.....

    It would be different if there were no alternative......glad we agree.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    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,

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    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.
    Last edited by figment; 11-29-2007 at 02:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •