Full Version: Enter key instead of mouse click.
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Renegade4
Hi gang,

I have a form with a textbox and a Submit button that launches a bunch of other stuff that is total irrevevant to my question.

Rather than the user clicking the Submit button, is there a way to trap a single press of the Enter key to fire the button OnClick event?

The default Enter key action is one Enter key press moves from the textbox to the Submit button (as if the Tab key was pressed)... a second Enter key press is then required to fire the button OnClick event.

I have tried trapping ASCII (13) in the On Key Press event, but I have a couple of users that are too impatient to wait the 1/2 second for the next form to load and end up pressing the Enter key multiple times which causes my code to crash since the On Key Press event keeps re-firing a query.

Any ideas?

thanks,
R4
michaela4
Why not put the code from the command button behind the AfterUpdate property of the textbox? When they hit enter it will fire the code. You can refine the code so that if you need certain criteria to be met before the code is fired you can do that.

HTH

Michael
Renegade4
Well DUH!!

Why is it always the simply obvious that we overlook????????

I got hit with this today in a db that has been up and running for over a year now. I haven't touched it in probably 3 months and am currently working on a much more complex project. I guess I should have worked on this after doing something basic rather than something complex.

Thanks Michael for reminding me to look at the basics.

R4
michaela4
Sounds like you've got your plate full. You should see some of the bonehead ??? I put out here. haha

You're welcome anytime.

Michael
tinygiant
You can also accomplish this by setting the command button's Default property to yes. This way, anytime Enter is hit anywhere on the form, except if another command button has focus, the default command button's code will run.

You can also set a Cancel button by setting the command button's Cancel property to True. It'll execute if you hit the Esc key.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.