Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How can I make a Command Button in VB6 run it's code upon a press of the ENTER/RETURN button on the keyboard?
I have built a web browser in VB, and have it fully functioning. The only thing I would like to add would be the ability to just press enter when in the text box for the address entry, and have the ENTER button activate the GO Command Button.
How can I make this work?
This is VB6, so it is older than later versions.
Please provide the code to do "Something" when ENTER is pressed
Thank you so much! Greatly Appreciated!
I have figured it out!
For future reference by anyone viewing this question later looking for an answer:
I used the code:
Private Sub txtAddress_KeyPress(KeyAscii As Integer) 'Be sure to change txtAddress to match your text box or other objects
If KeyAscii = vbKeyReturn Then 'You can use anything other than vbKeyReturn as well, for different buttons such as Up, Down, Left, Right buttons, etc.
cmdGo_Click 'This activates my command button GO, but you can put any code there.
End If 'This ends the If statement, and if you didnt know that, your probably shouldn't be programming. :P lol.
End Sub
I have figured it out!
For future reference by anyone viewing this question later looking for an answer:
I used the code:
Private Sub txtAddress_KeyPress(KeyAscii As Integer) 'Be sure to change txtAddress to match your text box or other objects
If KeyAscii = vbKeyReturn Then 'You can use anything other than vbKeyReturn as well, for different buttons such as Up, Down, Left, Right buttons, etc.
cmdGo_Click 'This activates my command button GO, but you can put any code there.
End If 'This ends the If statement, and if you didnt know that, your probably shouldn't be programming. :P lol.
End Sub
Sorry about the double post there for the same thing, Yahoo Answers went funny for a moment there.
Don't mean to confuse!
2 Answers
- Anonymous1 decade ago
Enable keypress for the form. (I don't have VB6 on this computer, and I forget the exact name of the property, but look under "key" something for the form). In the form's keypress event, if the key is Enter (13), call the button's click event.
- AJLv 71 decade ago
Well you can set the command button to be the default. That means when you press enter it like clicking the command button.