Subroutine for KeyPress?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<P>Hi,</P>
<P>I have this code to allow only numerical characters to be entered and currently it is only assigned to en text box when Im needing it to validate many:</P>
<P>Private Sub txtCustomerTel_Keypress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Or Chr(KeyAscii) = "-" Or Chr(KeyAscii) = "." Then To allow decimal numbers, backspaces and minus sign
Exit Sub
End If
If KeyAscii > Asc("0") And KeyAscii < Asc("9") Then do nothing if not a number pressed
Else
KeyAscii = 0
End If
End Sub</P>
<P>Is it possible to put this in a subroutine which is called by many different textboxes?</P>
<P>Cheers</P>
<P>Matt</P>

View the full article
 
Back
Top