Re: Restrict special characters

Tech-Archive recommends: Fix windows errors by optimizing your registry



It is often easier to define 'allowable' characters opposed to excluding
specific ones. See this as a common solution:
http://www.vb-helper.com/howto_allow_letters_numbers.html

The KeyPress event at that site has way too many lines of code for my taste. I would use this instead...

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr$(KeyAscii) Like "*[!a-zA-Z0-9]*" Then KeyAscii = 0
End Sub

--
Rick (MVP - Excel)

.



Relevant Pages

  • Re: Supress beep on characters
    ... but it still beeps on an C key. ... The MSDN library confirmed that .NET Compact Framework - Windows CE .NET Platform Note: The KeyPress event for combinations using the Ctrl-Shift keys is not provided. ... ignoreKey = False ... Private Sub treeLibrary_KeyPressHandles treeLibrary.KeyPress ...
    (microsoft.public.pocketpc.developer)
  • RE: DataGridView, how to capture a cells KeyPress event
    ... we should unsubscribe the KeyPress event of the ... editing control when the current cell leaves focus. ... The following is the modified sample code. ... Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ...
    (microsoft.public.vsnet.general)
  • RE: DataGridView, how to capture a cells KeyPress event
    ... we should unsubscribe the KeyPress event of the ... editing control when the current cell leaves focus. ... The following is the modified sample code. ... Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ...
    (microsoft.public.vsnet.general)
  • Re: undo function
    ... The only place to trap that is in the *form* KeyPress event, but don't forget to set KeyPreview to Yes. ... Private Sub Form_KeyPress ... However, if someone hits the esc button a couple times to undo their changes, the function doesn't run. ...
    (microsoft.public.access.formscoding)
  • Re: Diff between KeyPress and KeyDown
    ... >> So, to answer my own question: The KeyPress event doesn't keep track of the state of the keyboard, whereas the KeyUp and KeyDown events do. ... > does for upper case (always the upper case key code) ... > Private Sub Text1_KeyDown ...
    (microsoft.public.vb.general.discussion)