PDA

View Full Version : Solved: Execute commandbutton by hitting the enter key



island17
08-19-2004, 11:29 AM
Hello Friends

I need help with what should be very simple, I just can't for the life of me see what I am missing. I created a form in Word with a textbox (textbox1) for a user to enter the name of a staffer. After hitting the enter key or clicking on the "Find" button (commandbutton1) the macro searches a file and displays the results in another text box (textbox2).
If I enter a name and click on commandbutton1, it works fine. If i just hit the "enter" key it first sets focus on commandbutton1, then I have to hit the "enter" key again to activate the search.
I would like to eliminate hitting the enter key twice.

The tabindex value for textbox1 is set to 0, and the tabindex value for commandbutton1 is set to 1.

I know it can be done, but could use some help.
Thanks in advance
island17 (russ)

village_alchemist
08-19-2004, 11:53 AM
I would like to eliminate hitting the enter key twice.


You could use the exit event on your textbox to execute your command button code:

private sub textbox1_exit()
call commandbutton1_click
end sub

TonyJollans
08-19-2004, 11:54 AM
Hi Russ,

I think you mean a CommandButton on a UserForm and if so, what you need to do is to set the Default property of the command button to True.

island17
08-19-2004, 12:36 PM
Tony

Thanks, Works like a charm. I knew it had to something easy.

How do we mark this one solved.

Russ

TonyJollans
08-19-2004, 12:44 PM
My pleasure!

I'll mark it solved.