Discussion:
How do I catch the "delete key" in a textbox?
(too old to reply)
alpine
2003-08-14 18:04:19 UTC
Permalink
I am trying to catch the delete key when pressed but it just is not
working, I have provided the sample code below to see the reaction but
when the key is pressed, nothing happens. Can anyone help? Thanks!
Have you tried testing for the delete key in the KeyDown or KeyUp
events of the textbox?

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'***@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
William Cruz
2003-08-14 18:20:18 UTC
Permalink
OOP, I FORGOT THE CODE.. SORRY GUYS



Private Sub Text3_KeyPress(KeyAscii As Integer)

Select Case KeyAscii

Case 0 To 32, 45, 46, 48 To 57

If KeyAscii = 8 Then

If Len(Text3.Text) <= 1 Then

Option17.Value = True

End If

Else
If KeyAscii = vbKeyDelete Then
MsgBox "The Delete Key was pressed"
End If


Option17.Value = False

End If

Case Else: KeyAscii = 0

End Select


End Sub


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Saga
2003-08-14 18:57:02 UTC
Permalink
BY delete key, I assume you are referring to the key labelled "Delete",
not the back space key.

Your Keypress event is catching ASCII 8, but this represents only
the backspae key, not the delete.

I believe that Brian is correct, you should check in the KeyUp/Down events
(one or the other). Also, in thiscase, you are looking at the KeyCodes,
which
is different from the ASCII codes.

Good luck!
Saga
Post by William Cruz
OOP, I FORGOT THE CODE.. SORRY GUYS
Private Sub Text3_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 0 To 32, 45, 46, 48 To 57
If KeyAscii = 8 Then
If Len(Text3.Text) <= 1 Then
Option17.Value = True
End If
Else
If KeyAscii = vbKeyDelete Then
MsgBox "The Delete Key was pressed"
End If
Option17.Value = False
End If
Case Else: KeyAscii = 0
End Select
End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Matt
2003-08-14 19:28:11 UTC
Permalink
I am trying to catch the delete key when pressed but it just is not
working, I have provided the sample code below to see the reaction but
when the key is pressed, nothing happens. Can anyone help? Thanks!
_KeyPress will not catch the Delete key. Add a textbox to a new project and
then this code:

Private Sub Text1_KeyPress(KeyAscii As Integer)
Debug.Print KeyAscii
End Sub

You'll see that you don't get a keypress event when you press delete.
Loading...