+ Reply to Thread
Results 1 to 3 of 3

Code help appreciated:Code runs fine

  1. #1
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Code help appreciated:Code runs fine

    I have multiple textboxes on multiple forms that use the following code to restrict character input. Have tried setting up duplicate code in a standard module (also below) but it doesn't work. Code runs fine, but I can still enter any character in the userform text box. Any idea what I'm doing wrong?

    Private Sub txtYr2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case KeyAscii
    Case Asc("0") To Asc("9")
    Case Else
    KeyAscii = 0
    End Select
    End Sub

    Private Sub txtYr3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case KeyAscii
    Case Asc("0") To Asc("9")
    Case Else
    KeyAscii = 0
    End Select
    End Sub


    Here is what I've tried (setting up code in standard module 7):

    Sub RestrictChar ()

    Select Case KeyAscii
    Case Asc("0") To Asc("9")
    Case Else
    KeyAscii = 0
    End Select
    End Sub

    In the userform code:

    Private Sub txtYr2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    Module7.RestrictChar

    End Sub


    Cheers

    Peter

  2. #2
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    try this

    Please Login or Register  to view this content.
    Then in your module

    Please Login or Register  to view this content.
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

  3. #3
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Thanks Steve

    Works fine!

    Cheers

    Peter

+ 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