WRATH
02-27-2005, 04:31 PM
i need to call a function when only the enter button is pressed in a particular text box.
after the user enters the data in the text box, instead of them clicking the command button i would like to have the option of pressing enter after typing and either setfocus the command button in which holds the function im calling or just call the function.
MikeJ
02-27-2005, 04:33 PM
Two options.
#1
In the KeyPress event, check to see if KeyAscii = 13. If so, enter was pressed.
#2 (Better option)
In the KeyDown event, check to see if the KeyCode was vbKeyReturn. If so, enter was pressed.
Squishy
02-27-2005, 04:35 PM
You can also set the button's Default property to True.
WRATH
02-27-2005, 04:36 PM
do i have to make an object of KeyAscii and use that for the check?
and what key event am i using? down, up..etc
Squishy
02-27-2005, 04:40 PM
KeyAscii is a value passed to the KeyDown and KeyUp events. I like using KeyUp more than KeyDown because that makes sure the event only fires once, even if the user holds down the enter key too long.
MikeJ
02-27-2005, 04:41 PM
No. Use KeyDown or KeyUp, it doesn't matter. It's a parameter - it will be automatically available to you in that sub.
WRATH
02-28-2005, 09:29 AM
No. Use KeyDown or KeyUp, it doesn't matter. It's a parameter - it will be automatically available to you in that sub.
so how do i know what key is the enter key?
KeyAscii = "enter"
or
KeyAscii = 13
'where can i get a list of all the keys numerical val?
Squishy
02-28-2005, 05:06 PM
Check if KeyCode = vbKeyReturn. KeyAscii belongs to the KeyPress event.
If KeyCode = vbKeyReturn Then
MsgBox "Enter pressed"
End If
MikeJ
02-28-2005, 05:58 PM
MSDN has these constants, as does the Object Browser.
WRATH
02-28-2005, 09:05 PM
i can never find anything on msdn, i swear it takes a genius to use that site...
Squishy
02-28-2005, 10:02 PM
This takes you directly to the VB6 Reference Library (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/VBRef98/html/vbmscLROverview.asp)