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
Bookmarks