+ Reply to Thread
Results 1 to 3 of 3

Validation in userform

  1. #1
    Gert-Jan
    Guest

    Validation in userform

    In a textbox of my userform only the comma and digits are allowed. But, the
    user must not be able to make long entry: such as 1,65647. Only two digits
    AFTER the comma are allowed. Digits on the third position must be deleted.
    Can someone help?



  2. #2
    Bob Phillips
    Guest

    Re: Validation in userform

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    With Me.TextBox1
    Select Case KeyAscii
    Case 44: ' comma
    If Len(.Text) - Len(Replace(.Text, ",", "")) >= 1 Then
    MsgBox "Too many commas"
    KeyAscii = 0
    End If
    Case 48 To 57: '0-9
    If InStr(.Text, ",") > 0 Then
    If InStr(.Text, ",") = Len(.Text) - 2 Then
    MsgBox "Only 2 dec places"
    KeyAscii = 0
    End If
    End If
    End Select
    End With

    End Sub


    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "Gert-Jan" <[email protected]> wrote in message
    news:[email protected]...
    > In a textbox of my userform only the comma and digits are allowed. But,

    the
    > user must not be able to make long entry: such as 1,65647. Only two digits
    > AFTER the comma are allowed. Digits on the third position must be deleted.
    > Can someone help?
    >
    >




  3. #3
    Gert-Jan
    Guest

    Re: Validation in userform

    Thanks, this works great!!

    "Bob Phillips" <[email protected]> schreef in bericht
    news:[email protected]...
    > Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    > With Me.TextBox1
    > Select Case KeyAscii
    > Case 44: ' comma
    > If Len(.Text) - Len(Replace(.Text, ",", "")) >= 1 Then
    > MsgBox "Too many commas"
    > KeyAscii = 0
    > End If
    > Case 48 To 57: '0-9
    > If InStr(.Text, ",") > 0 Then
    > If InStr(.Text, ",") = Len(.Text) - 2 Then
    > MsgBox "Only 2 dec places"
    > KeyAscii = 0
    > End If
    > End If
    > End Select
    > End With
    >
    > End Sub
    >
    >
    > --
    >
    > HTH
    >
    > Bob Phillips
    >
    > (replace xxxx in the email address with gmail if mailing direct)
    >
    > "Gert-Jan" <[email protected]> wrote in message
    > news:[email protected]...
    >> In a textbox of my userform only the comma and digits are allowed. But,

    > the
    >> user must not be able to make long entry: such as 1,65647. Only two
    >> digits
    >> AFTER the comma are allowed. Digits on the third position must be
    >> deleted.
    >> Can someone help?
    >>
    >>

    >
    >




+ 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