PDA

Click to See Complete Forum and Search --> : Enter


hasandak
Mar 22nd, 2001, 03:56 AM
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?

Mar 22nd, 2001, 06:18 AM
Put this in the Form_KeyPress event or any KeyPress event.



If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"

PunK
Mar 22nd, 2001, 07:18 AM
Private Sub TheTHINGY#_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 then SendKeys "{tab}"
End Sub

Mar 22nd, 2001, 03:24 PM
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.

Mar 22nd, 2001, 05:53 PM
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.

Lord Orwell
Mar 25th, 2001, 05:35 AM
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.

zuperman
Mar 25th, 2001, 09:12 PM
just a correction:


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

Lord Orwell
Mar 26th, 2001, 01:13 AM
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.