Results 1 to 4 of 4

Thread: Question about restriction

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    1

    Post

    How do you make it so that you can type backspace in a textbox after you've limited the textbox to only numbers.

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    Use the keypress method on the field in qustion to run the following (the second if statement should be modified if you don't want the user to enter "," or "." characters)

    Code:
    
    If KeyAscii< Asc("0") Or KeyAscii> Asc("9") Then
        If KeyAscii = Asc(",") Or KeyAscii = Asc(".") Or KeyAscii = 8 Then
          'nothing, we will allow these characters
        Else 'the user has pressed some key other than 0-9 or "," or "." or backspace
            KeyAscii = 0 ' cancel the character
            field.SelStart = 0
            field.SelLength = Len(field)
            Beep
        End If
    End If

  3. #3
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Look into the MaxLength property also.

    ------------------
    Tom Young, 14 Year Old
    [email protected]
    ICQ: 15743470
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  4. #4
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226

    Post

    Try this Function. Credit goes to Aaron Young
    [/code]

    Function Num_Bksp_Only(ByVal KeyAscii As Integer) As Integer
    If KeyAscii = vbKeyBack Or IsNumeric(Chr(KeyAscii)) Then
    Num_Bksp_Only = KeyAscii
    End If
    End Function

    [code]

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