-
I'm quite new to VB so please excuse this question.
I have a textbox on a form. Users may access the textbox and delete what's in it (by hitting backspace / delete) but may not edit the field otherwise.
Right now I check the key in the keypress event. If it isn't backspace or delete I change the keyascii to vbkeyescape. This works but I'm sure there is a better way to do this.
Any suggestions?
-
Don't set it to vbKeyEscape, just set KeyAscii to 0 to disable the event. Otherwise a spurious Escape keycode will appear.
-
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> vbKeyBack Then KeyAscii = 0
End Sub