-
when i press backspace, the code fires up
but how come when i press DELETE nothing happens?
Code:
Private Sub lstRange_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Then
MsgBox "hi"
lstRange.RemoveItem lstRange.ListIndex
End If
End Sub
-
You need to do this
Code:
Private Sub lstRange_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then
MsgBox "hi"
End If
End Sub
Private Sub lstRange_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Then
MsgBox "hi"
End If
End Sub
-
just curios
isn't vbKeyDelete fired on keypress? seems not to be
do you know why thou?
since vbKeyBack is fired...
thanks for the help anyways
i will test what ya just gave me
-
Well, actually, you can do this, too.
Code:
Private Sub lstRange_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Or KeyCode = vbKeyBack Then
MsgBox "hi"
End If
End Sub
I guess the reason why it doesn't work in the Keypress sub because the VB doesn't count the delete key as an ascii key like alphabets or numeric letters.
-
KeyAscii can be used as well.
Code:
Private Sub lstRange_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8 Or 46
MsgBox KeyAscii
End Select
End Sub
Or KeyCode can be used:
Code:
Private Sub lstRange_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyBack Or vbKeyDelete
MsgBox KeyCode
End Select
End Sub
-
Hi Matthew,
Are you sure that your code in the KeyPress sub work? I tried it and it didn't work as I expected because it is the same thing as Kovan code. Moreover, constant keycode, such as vbKeyDelete or vbKeyReturn, etc., give you an integer value. Therefore, I don't think it will make different between pure numeric type like you did and enum type, such as vbKeyBack.