Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Run Code When User Presses "Enter" in Text Box

Status
Not open for further replies.

tbaguio

Programmer
Sep 25, 2000
41
CA
Hi,

I have a form where the user enters some info into a text box and then clicks on a command button marked "OK" to proceed. They now want to enable a shortcut by running the same code when enter is pressed while in the textbox itself. So instead of typing and clicking the button, they want to type in the text box and then hit "Enter". I think it involves the On Key Press event, but I'm not sure how to adopt it.

Thanks,
Theresa "Sleep is the best meditation." - Dalai Lama
 
Hi Theresa!

Actually you can do this by going to the properties of the button and on the other tab you should see a line called default. Set default to yes and now when enter is pressed anywhere on the form it will be just like clicking that button. Please note that this will work from any control on the form now, not just the test box.

hth
Jeff Bridgham
 
Hi,

To do exactly what you want Theresa it's quite simple if you are able to use a little VB code.

On the On KeyPress action as you said.

you should use something like

if KeyAscii = 13 then 'If ENTER is pressed
call Your_Sub
end if

when the user will press enter you will run the code of your sub.

I wish that helps!

Rick
 
Hi,

Thanks for both of your input. That worked great!

Theresa "Sleep is the best meditation." - Dalai Lama
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top