PDA

View Full Version : VBA form events



JKwan
01-12-2012, 07:04 AM
I would like to use the Up and Down arrow keys to navigate my form to go to Next and Previous records. However, I am running into a problem. If I have a blank form the UserForm_KeyPress and UserForm_KeyDown get triggered, this is what I need to process the keycode. However, if I were to put a text box onto the form and run the form, the events do not fired? Is my form not getting the focus, if so, how do get set the focus to the form so the events get triggered? Or am I totally in the left field? The need is to capture "key press" anywhere when the form is running, this is the basic need for me to solve, thanks.

Bob Phillips
01-12-2012, 07:59 AM
When you have controls on a form, the form doesn't get focus. You could set TabStop to False for all controls, but that provides limited relief.

JKwan
01-12-2012, 08:08 AM
Thanks xld, does this mean that I am toast in terms of doing what I need?

Bob Phillips
01-12-2012, 10:02 AM
I would just put a next and previous button on the form. That's how I do it.

Jan Karel Pieterse
01-12-2012, 10:39 AM
Or use tab and shift+tab perhaps.

JKwan
01-12-2012, 11:56 AM
Or use tab and shift+tab perhaps.

How would one use the tab / shift tab scenario? Wouldn't I run into the same problem as to how I would catch what the keys are being hit?

JKwan
01-12-2012, 12:03 PM
I would just put a next and previous button on the form. That's how I do it.

Currently, this is how I am doing it. With the up/down keys, this is another way to navigate. I like to use the keyboard far more than the mouse.....

Kenneth Hobs
01-12-2012, 03:08 PM
Similar to xld's approach, you can put an Accelerator in a command button control. I would use N and P for Next and Previous buttons. Alt+letter would then activate the button's click event.

Jan Karel Pieterse
01-16-2012, 01:12 AM
How would one use the tab / shift tab scenario? Wouldn't I run into the same problem as to how I would catch what the keys are being hit?
I'm sorry, I misread the question!