How can I make the Enter key to act like tab
so the user will be able to navigate
with the tab and also with the Enter key?
Printable View
How can I make the Enter key to act like tab
so the user will be able to navigate
with the tab and also with the Enter key?
Put this in the Form_KeyPress event or any KeyPress event.
Code:If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
Private Sub TheTHINGY#_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 then SendKeys "{tab}"
End Sub
Quote:
Originally posted by PunK
Private Sub TheTHINGY#_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 then SendKeys "{tab}"
End Sub
Exactly the same, 13 is the key code constant for vbKeyReturn. Best to use the constants instead of the key numbers.
It's not "best to use them" really, rather it's a matter of preference. Although it makes code somewhat unproper to some, I tend to use numbers more than constants.
as do i.
Although in that case you get lucky because vbkeyreturn is the scancode number, not the ascii number. They just happen to be the same for the enter button.
perhaps this code will work slightly better:
Private Sub DestTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
if keycode = vbkeyenter then keycode = vbkeytab
end sub
It actually convinces the program that you pressed the tab instead of the enter key. The other samples said you pressed it in addition to the enter key.
just a correction:
Code:Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
SendKeys "{TAB}"
End If
End Sub
keyascii=0
this way it disables that annoying beep when u hit the enter key
hmm. i had an error in mine anyway.
I named a constant wrong, and it doesn't work with text boxes. :(
vbkeyreturn should have been vbkeyenter (to start with).
None of the other codes caused a beep.