+ Reply to Thread
Results 1 to 4 of 4

validation of textbox entries

  1. #1
    CG Rosén
    Guest

    validation of textbox entries

    Good Day Group,

    Found below code in this group. It works fine except that the SetFocus
    command does not work.
    The focus jumps to TextBox2 as set in the "Tab order".

    What Iám looking for is a code that validates the TextBox and give a warning
    when a letter is entered
    in the box, single or mixed with numbers. Only numbers ín any combination
    shall be the correct input.

    Grateful for help.

    Brgds

    CG Rosén

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox1.TextLength = 0 Then
    Cancel = True 'to prevent non-entry
    Else
    With Sheet1.Range("c1:c99")'Where valid entries are located
    Set c = .Find(TextBox1.Text)
    If c Is Nothing Then
    MsgBox TextBox1.Text & " is invalid input"
    TextBox1.SetFocus
    Exit Sub
    End If
    End With
    End If
    End Sub





  2. #2
    Toppers
    Guest

    RE: validation of textbox entries

    Hi,
    Try thiS:

    If Not (IsNumeric(TextBox1.Value)) Then
    MsgBox "Entry must be numeric"
    Exit Sub
    End If

    "CG Rosén" wrote:

    > Good Day Group,
    >
    > Found below code in this group. It works fine except that the SetFocus
    > command does not work.
    > The focus jumps to TextBox2 as set in the "Tab order".
    >
    > What Iám looking for is a code that validates the TextBox and give a warning
    > when a letter is entered
    > in the box, single or mixed with numbers. Only numbers Ă*n any combination
    > shall be the correct input.
    >
    > Grateful for help.
    >
    > Brgds
    >
    > CG Rosén
    >
    > Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    > If TextBox1.TextLength = 0 Then
    > Cancel = True 'to prevent non-entry
    > Else
    > With Sheet1.Range("c1:c99")'Where valid entries are located
    > Set c = .Find(TextBox1.Text)
    > If c Is Nothing Then
    > MsgBox TextBox1.Text & " is invalid input"
    > TextBox1.SetFocus
    > Exit Sub
    > End If
    > End With
    > End If
    > End Sub
    >
    >
    >
    >
    >


  3. #3
    keepITcool
    Guest

    Re: validation of textbox entries


    can shorten that to:

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Cancel = Not IsNumeric(TextBox1) Or _
    IsError(Application.Match(CDbl(TextBox1), Sheet1.Range("c1:c99"), 0))
    If Cancel Then Beep
    End Sub




    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    CG Rosén wrote :

    > Good Day Group,
    >
    > Found below code in this group. It works fine except that the
    > SetFocus command does not work. The focus jumps to TextBox2 as set
    > in the "Tab order".
    >
    > What Iám looking for is a code that validates the TextBox and give a
    > warning when a letter is entered in the box, single or mixed with
    > numbers. Only numbers ín any combination shall be the correct input.
    >
    > Grateful for help.
    >
    > Brgds
    >
    > CG Rosén
    >
    > Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    > If TextBox1.TextLength = 0 Then
    > Cancel = True 'to prevent non-entry
    > Else
    > With Sheet1.Range("c1:c99")'Where valid entries are located
    > Set c = .Find(TextBox1.Text)
    > If c Is Nothing Then
    > MsgBox TextBox1.Text & " is invalid input"
    > TextBox1.SetFocus
    > Exit Sub
    > End If
    > End With
    > End If
    > End Sub


  4. #4
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,165
    Can I get some help on expanding this code? Even direction will be useful as I don't mind learning by reading examples (Yes, I have searched for many hours).

    (snippet)
    If Not (IsNumeric(TextBox1.Value)) Then
    MsgBox "Entry must be numeric"
    Exit Sub
    End If

    I have a userform with 2 to 100 textbox's to itterate thru for a numeric condition to be true less one text box which will be a Date. Can this be coded to check all textbox's less one (call it textbox1) with out specifying every textbox?

    In the above code TextBox1.Value will have to be a variable.
    Last edited by Rick_Stanich; 02-17-2006 at 06:49 PM.
    Regards

    Rick
    Win10, Office 365

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1