Results 1 to 5 of 5

Thread: [RESOLVED] validation of a text box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    182

    Resolved [RESOLVED] validation of a text box

    hi i have a text box which does not have to exceed 10 characters code below:

    Code:
    If Len(text1.Text) > 10 Then                      
       MsgBox "text box 1 length out of range"    
    End If
    so when i type in some text and EXCEED the length of the text box (10) it gives me an message box. which is what i want. BUT after the message box has appeared i can click ok and happily type more characters in. so i was wondering what code i will need so there for more data cannot be entered and if it is then an error message appears?
    thanks in advance

  2. #2
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: validation of a text box

    try like this
    Code:
    Private Sub Text1_Validate(Cancel As Boolean)
        If Len(Text1.Text) > 10 Then
           MsgBox "text box 1 length out of range"
           Cancel = True
        End If
    End Sub
    EDIT:

    Also, if use set MaxLength property to 10 for the text box, this could be done, Only thing you wont get the message box.
    IIF(Post.Rate > 0 , , )

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    182

    Re: validation of a text box

    it does not work how i want it to work.

    at the moment i have a text box which has a length of 10 characters, and if i exceed the number of characters, then an error message appears but after clicking ok i can add more characters i have tried to use max length but i want the text box NOT to be able to accept more characters and not to give a system beep, but an error message.

    thanks for the quick reply.

  4. #4
    New Member
    Join Date
    Jun 2008
    Posts
    1

    Smile Re: validation of a text box

    try this:
    Code:
    Private Sub Text1_LostFocus()
        If Len(Text1) > 10 Then
            MsgBox "larger than 10, please enter again", vbExclamation
            Text1.SetFocus
        End If
    End Sub
    if you leave this text box, an error msg will be popped up. hope this helps

  5. #5
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: validation of a text box

    @ tjroamer
    If you have noticed, the Validate event does the same.
    Only thing is its the proper place for it and it supports the Cancel parameter which cancel the focus change.


    @adam786
    Why it doesnt work like you want?
    IIF(Post.Rate > 0 , , )

Posting Permissions

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



Click Here to Expand Forum to Full Width