Consulting

Results 1 to 6 of 6

Thread: Solved: Limit character input in a textbox

  1. #1
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location

    Solved: Limit character input in a textbox

    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?
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    [vba]
    Private Sub UserForm_Initialize()
    Me.TextBox1.MaxLength = 200
    End Sub
    [/vba]

  3. #3
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    IF you want to give the user a little feedback, then
    [VBA]Private Sub TextBox1_Change()
    If TextBox1.TextLength > 10 Then
    MsgBox "Too long"
    TextBox1.Text = Left(TextBox1.Text, TextBox1.TextLength - 1)
    End If
    End Sub[/VBA]Leave the Maxlength at 0 and let this sub manage it.

    David


  4. #4
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Perfect... Thanks
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  5. #5
    VBAX Newbie
    Joined
    Sep 2014
    Posts
    1
    Location
    Hi there. I get an "object required" error message if I try running that code. Has anyone else had the same issue?

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by JJF View Post
    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

Posting Permissions

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