bokaraton Posted February 18, 2004 Posted February 18, 2004 Does anyone know how to code this for vb.net? I'd like to prevent the users from keying in alpha characters. Private Sub txtRec_KeyPress(KeyAscii As Integer) If Chr$(KeyAscii) Like "[!0-9" & Chr$(vbKeyBack) & Chr$(46) & "]" Then If KeyAscii = 13 Then KeyAscii = 0 'get rid of beep If txtRec.Text > rs.RecordCount Or txtRec.Text < 1 Then txtRec.Text = rs.AbsolutePosition Else rs.Move txtRec.Text - 1, adBookmarkFirst Call FillForm End If Else KeyAscii = 0 'ignore the keystroke Beep End If End If End Sub Quote
*Experts* mutant Posted February 18, 2004 *Experts* Posted February 18, 2004 If you do not want the users to enter letters then you can check the if the key pressed was a number using the IsNumber shared method of the Char. Then you pass in the keychar passed into the event. If Not Char.IsNumber(e.KeyChar) Then e.Handled = True End If Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.