UserForm keypress event help

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: UserForm keypress event help

  1. #1
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,853
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default UserForm keypress event help

     
    Hi

    I am trying to restrict text in a textbox on a userform. So I use

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

    End Sub

    This works fine, but I have like 20 textboxs on one userform and I wanted to not have to put this code 20 seperate times.

    I tried

    Private Sub Userform1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

    End Sub

    but it didnt seem to work. Like I said it will work fine if I report the code 20 times once for each textbox, but is there a simple way to include all the textboxs as one?

    Thanks

    Jacob

  2. #2
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: UserForm keypress event help

    Please keep all posts to the original thread.

    http://www.mrexcel.com/board2/viewtopic.php?t=64518

  3. #3
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,853
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: UserForm keypress event help

    This is a different question

  4. #4
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: UserForm keypress event help

      
    http://www.mrexcel.com/board2/viewtopic.php?t=53597

    NOTE: Different question, but related topic. Multiple threads slow down the board. Please keep all related questions to the same thread.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com