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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

userform - detecting enter/return 2

Status
Not open for further replies.

electricpete

Technical User
Oct 1, 2002
289
US
Newbie question.

I have created my first userform. It has several items for the user to enter and at the bottom a commandbutton labeled "ok" which the user is supposed to press when finished entering the data. The commandbutton saves the data and unloads the userform

Is there a way that the commandbutton can be excecuted when the user presses "enter" ? (so the user doesn't have to mouse-click on the command button).

I see there is provision for a single letter to be used with alt (accelerator), but I would like this "ok" commandbutton to be triggered with the enter key instead.

Thanks in advance.
 
When the command button has the focus, enter/return will trigger its click event.

Right clicking on the form in design view will provide you the option of setting the tab order of all the controls on the form.

Move the "ok" button so that it is after the last data entry control. Then when you tab out of the data entry, the "ok" button will receive the focus, and enter will make it do its thing.
 

Also, check 2 properties of CommandButton:
Default and Cancel, both set to False by default.

You can have 1 command button with Default property set to True, the same goes for Cancel property.

If you set Default to True, this command button will be 'click' when you hit Enter key, no matter which control has a focus.

Cancel property is triggered by hitting Esc key.

Have fun.

---- Andy
 
Good one Andy. electricpete, this is a good route but you first need to assess if the Enter key is (or can) be used legitimately elsewhere, say in a textbox.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top