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

Catching pressing "ENTER" key on VBA form (Excel) 1

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
Is there a way to catch the event when a user hits "ENTER" on a form? As with many forms, I just want to process something when the user hits ENTER. (Instead of having to click the "OK" button, etc). The user may actually be inside of a different control at the time (textbox, combobox, etc).
 
You can set your OK button 'Default' property to true, when Enter will run any code in the Click event.


Regards
BrianB
Use CupOfCoffee to speed up all windows applications
================================
 
Hi
You could use the KeyDown Event to trap the usage. I think you will have to add the code to this event of each control on the form.

eg for the form itself
Code:
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then 'Enter
    'do stuff
End If
End Sub

Good Luck
;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
BrianB,
Perfect! Exactly what I was looking for.

Loomah,
I'll keep that in mind... in may come in handy some other time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top