Thursday, August 21, 2008

Numeric only in Textbox

I have function code here. To restrict the input in textbox only for numeric.

Public Function OnlyNumericKeys(KeyAscii As Integer, TextBox As control) As Integer

Select Case KeyAscii
Case 8, 48 To 57, 46 And InStr(TextBox, ".") = 0
Case 45 And InStr(TextBox, "-") = 0

If TextBox.SelStart > 0 Then
KeyAscii = 0
End If
Case Else

KeyAscii = 0

End Select
OnlyNumericKeys = KeyAscii

End Function


Thanks for the help of my friend (mike).

No comments: