|
-
Mar 22nd, 2001, 04:56 AM
#1
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, 07:18 AM
#2
Put this in the Form_KeyPress event or any KeyPress event.
Code:
If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
-
Mar 22nd, 2001, 08:18 AM
#3
Member
Or this way...not much difference tho
Private Sub TheTHINGY#_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 then SendKeys "{tab}"
End Sub
-
Mar 22nd, 2001, 04:24 PM
#4
Re: Or this way...not much difference tho
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, 06:53 PM
#5
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.
-
Mar 25th, 2001, 06:35 AM
#6
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.
-
Mar 25th, 2001, 10:12 PM
#7
Frenzied Member
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
-
Mar 26th, 2001, 02:13 AM
#8
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|