Trapping Onkey or Keypress in UserForm : please help 
Author Message
 Trapping Onkey or Keypress in UserForm : please help

I have set up a UserForm for data entry/modification that fires up
when I click any row on a sheet. The UserForm displays all the fields
on that particular row in the form of comboboxes and textboxes.
I would like to be able to change rows just by pressing Alt-Up or
Alt-Down. The pseudo code for this would be something like :

Detect Alt-Up/Alt-Down anywhere in Userform
Hide ? or Unload ? Userform
Move Up/Down one row in worksheet
Load ? Show ? Repaint ? Userform with new row's fields
(If possible, position cursor in same control as it was on previous
row/form).

Onkey appears not to work when focus is on any Userform control.
Reading Usenet archives, I seem to remember someone recommending the
use of Keypress, with a caveat for Textboxes (easier for buttons than
for textboxes?), but I can't relocate that particular post. I think it
had something to do with creating a class module.

What is the coding logic for this problem (where do I put the code,
what is the code, is there any danger of recursive behaviour, i.e.
when the form on the "new" row unloads as a result say of clicking OK
or Cancel, will control pass back to the "initially selected
row/form"... etc) ?

Any help would be much appreciated. TIA.

Richard



Wed, 25 Aug 2004 21:15:44 GMT  
 Trapping Onkey or Keypress in UserForm : please help
Richard,

Every control and UserForm has a KeyPress event. For me these didn't fire
with Alt-Up or
Alt-Down, though they do with other keystrokes. However, given what you want
to do, I believe that a SpinButton is a great solution. Use its SpinUp and
SpinDown events to navigate the rows on the worksheet.

HTH,
Merjet



Wed, 25 Aug 2004 22:44:55 GMT  
 Trapping Onkey or Keypress in UserForm : please help
Merjet,

Thanks for your useful feedback, yes, I see your point about
Spinbutton, I'll try it. (I would have liked a keyboard solution, not
being a great mouse fan, and also because I designed this routine for
rapid data entry/modification so that my hands wouldn't have to leave
the keyboard).

Quote:

>Richard,

>Every control and UserForm has a KeyPress event. For me these didn't fire
>with Alt-Up or
>Alt-Down, though they do with other keystrokes. However, given what you want
>to do, I believe that a SpinButton is a great solution. Use its SpinUp and
>SpinDown events to navigate the rows on the worksheet.

>HTH,
>Merjet



Thu, 26 Aug 2004 00:44:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Trapping OnKey Event in a Excel COM AddIn

2. Help for OnKey please

3. Application.OnKey question - please help

4. Onkey help please....

5. Trapping keypress or KeyDown in worksheet

6. Trap Page-Down KeyPress

7. Trap Keypress to igmore non numeric entries

8. Trapping KeyPresses - Still Having difficulties

9. Trapping KeyPresses

10. Onkey in userform


 
Powered by phpBB® Forum Software © phpBB Group