Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...