How to recognize which key being pressed in VBA.

I have an unbound entry form in my Access 2013 application.  The user has to enter information about an item, submit the information and then enter information about another item into the same form.  This is a high volume data entry process.

Currently I have a 'Submit' button at the bottom of the form.  When the user clicks 'Submit', the data is edited and then written to the appropriate table.

All of the entry on the form can be done from the keyboard.  The way I have it set up now, after entering the data the user must take one hand off the keyboard and click the mouse on the 'Submit' button.  This is slowing them down and they have large data volumes to input.

I thought of having the 'Submit' button be the next tabstop after the last data field on the screen.  That doesn't work some of the time becasue some data is optional and they may or may not enter anything into the data field that precedes the SUbmit button in the tab order.

I've never worked with trapping keys strokes to initiate an action but I've seen Access application where it has been done.  The one I saw It was set up to submit the data on the screen by pressing the 'PageDown' key.

If I wanted to allow the user to press the 'Enter', 'PageDown'  (Or any key) key to submit the form, how and where in the VBA code  would I recognize that they pressed the 'Enter' key, so I could take the same actions as though they had clicked the 'Submit' button with the mouse?
LVL 1
mlcktmguyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
hi Mick,

if you want to trigger command button with ENTER, that is easy ... set the Default property on the Other tab to Yes

btw, the Cancel property does the same thing for the ESCape key ...

have an awesome day,
crystal
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorieAnalyst Assistant Commented:
Why not add a shortcut for the Submit button?

You can easily do that by changing the caption of the button.

For example if the caption is currently Submit if you change it to &Submit then the user can use ALT+S to 'click' the button.
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
thinking along the same lines, Norie ... added this but didn't get editing submitted before you commented ...

you can also set an ALT-hotkey up by prefacing a letter in the Caption property of the button with & 
for instance: Caption = &Submit means Alt-S will be hotkey
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
If I wanted to allow the user to press the 'Enter', 'PageDown'  (Or any key) key to submit the form, how and where in the VBA code  would I recognize that they pressed the 'Enter' key, so I could take the same actions as though they had clicked the 'Submit' button with the mouse? 

Open in new window

alternatively, try look for KeyDown or KeyPress event but you got to place that event in every controls.

Form.KeyDown Event (Access)
https://msdn.microsoft.com/en-us/vba/access-vba/articles/form-keydown-event-access
look for KeyCode = 13 for {Enter} key

Form.KeyPress Event (Access)
https://msdn.microsoft.com/en-us/vba/access-vba/articles/form-keypress-event-access
look for KeyAscii = 13 for {Enter} key

@crystal,
do you mean set Enter Key Behavior to Default?
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
@Ryan, no, there is a property on the Other tab of the property sheet called "Default". Its purpose is to identify a default command button for the Enter key.  Only one command button can be the default -- if another is set, the first one becomes No.  If, however, there is more than one command button and another one has the focus, pressing Enter will execute the Click event of that one instead.

CommandButton.Default Property (Access)
https://msdn.microsoft.com/en-us/VBA/Access-VBA/articles/commandbutton-default-property-access
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
@crystal

ah, ok. think we are referring to different controls :)
0
mlcktmguyAuthor Commented:
Thanks, I had no idea those options were available.
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, mick ~ happy to help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.