I wanted to disable the BackSpace and Delete keys in a TextBox. As a simple example I created a form with a single TextBox and added the following code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyBack: KeyCode = 0
Case vbKeyDelete: KeyCode = 0
It disables the Delete key but has no effect on the BackSpace key.
So then I ERASED the KeyDown code (above) and substituted the following code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyBack: KeyAscii = 0
Case vbKeyDelete: KeyAscii = 0
In this case it disables the BackSpace key but has no effect on the Delete key!
What gives! When disabling keys, how do I know whether to put the code in KeyPress or KeyDown events?