Here's my dilema. I find myself always running into problems when using the KeyPress, KeyDown, KeyCode, KeyUp..Can anyone tell me when to use one over the other?? Little confused on this subject. Thanks
Printable View
Here's my dilema. I find myself always running into problems when using the KeyPress, KeyDown, KeyCode, KeyUp..Can anyone tell me when to use one over the other?? Little confused on this subject. Thanks
Try and do everything in the Validate instead of the Key... events. If you must use the Key... events, use KeyPress if you don't care about modifier keys (alt, shift, ctrl) - otherwise, use the KeyDown.
Some people use the change event instead. If you do, be careful about modifying the text in the textbox, because that will fire off another change event.
One thing for sure, if you want to Cancel a users input, you should use KeyPress, because you can set the KeyAScii to 0:
You can use the KeyDown & KeyUp to notice if someone's holding the keys.Code:Sub Text1_Keypress(KeyAscii As Integer)
If Keyascii = vbKeyA then KeyAscii = 0 'if the user types a, eat it and don't let it to the textbox :)
end Sub
Code:Private holding As Boolean
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
holding = True
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If holding Then MsgBox "you held the button for and released it :)"
holding = False
End Sub
Thank you for setting me straight :)