Command button and 'Enter'

Anna Anna

Registered User.
Local time
Today, 13:10
Joined
Jan 26, 2003
Messages
17
Hi!
Any idea how to execute click event procedure on command button by hiting
'Enter' on a keybord instead to click on that button?
Thanks for your help.
Anna
 
Last edited:
Here's a start...

On your Form properties, on the Event tab, set KeyPreview to Yes.

Next, make sure your command button has its Click event set to [Event Procedure] to run whatever it is you want to run when it's clicked.

Now, go back to the Form's Event tab and create an event procedure for the 'On Key Down' event. Here's the code you can paste (just substitute in the name of your command button where I've put 'cmdButton'):
Code:
If KeyCode = vbKeyReturn Then
    cmdButton_Click
End If
I suspect that you may want to further control the use of your 'Enter' key, but this should get you started.

I may have misunderstood if all you want to do is 'SetFocus' to your command button by hitting 'Enter'. If that is the case, you'd just substitute the 'cmdButton_Click' line above with 'cmdButton.SetFocus'.

HTH,
John
 
Thanks.
I tried,but something is not working. I am geting only focus on that button.
What am I doing wrong?
Anna
 
What are you trying to do with the command button - what do you want to happen when user hits the 'Enter' key?
 
Hi jjturner!
Thanks! I have already got it. I got advise to change command button deffult property to 'yes' and that works perfectly.
thanks again.
Anna
 
Hi!
I build a form that include many command buttons. such as Next Record, Previous Record, Find Record, Close Form e.t.c
i want to press command button with a keyboard key not with mouse click.
for example 1:i want to press Find Record button with "Ctrl+F" key combination.
2: to press Next Record button with "Right Arrow" key (i think its code is 16).
3: to press Previous Record button with “Left Arrow” Key. Etc.
Please help me. Thanks in advance.
 

Users who are viewing this thread

Back
Top Bottom