accelerator key

  • Thread starter Thread starter Betsy
  • Start date Start date
B

Betsy

Guest
I have a database set up for an order entry dept in which they mainly use the number keypad. The users would like to use the "+" key on the #keypad to tab between fields in the database. They currently use this key in some of our other programs and would like to stay consistant. Can this be done? How? I tried to set the "+" key as a hot key, but must be using the wrong syntax.
 
It's faster to keep your hand on the number keypad than to reach across the keyboard for the tab key (they use their left hand to turn pages while they are keying). I realize they could use the enter key on the number keypad to move from field to field, but the problem is that the team is using other software in which they use this "+" key to tab and they have been for years, our access database in new and would rather not have to reprogram everybody.
 
In the Form's Event tab of Properties, change Key Preview to Yes. Under On Key Press (the event immediately above that), place this in the code builder:
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 43 Then
        KeyAscii = 0
        SendKeys "{tab}"
    End If
End Sub

HTH,
David R

P.S. Make sure at the top you have the line "Option Explicit" after "Option Compare Database" or this will NOT work.


[This message has been edited by David R (edited 04-18-2002).]
 
I am designing a keypad, with command buttons cmd0, cmd1 etc having captions 0, 1 and so on. Is it possible to extend the above idea so that (only on this form), pressing "0" on the (physical) keyboard's numpad will trigger the On Click event for cmd0, pressing "1" will trigger the On Click event for cmd1 and so on?

I am trying to find ways to allow speedy operation, without necessarily having to use the mouse, press the Alt key or navigate around with Tab, arrow keys etc.

Thanks
Mike.
 
Yes - it's possible to do that - I just tried it with a test form containing a button and a textbox. The button's OnClick event code was:

Code:
Private Sub YourButton_Click()
MsgBox "The button was clicked!"
End Sub

The textbox OnKeyPress event code was:

Code:
Private Sub YourTextBox_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then YourButton_Click
End Sub

When the textbox has the focus and the space bar (ASCII 32) is pressed, the button click code is called.

NB:
-The button will not visually appear to be clicked on the screen when the event triggers
-This code only traps the keypress when the focus is in the one textbox - I tried putting it in the KeyPress event for the whole form, but it didn't trigger when the focus was inside a textbox - so you may need to add the code to each control that may be active when you want the function to be active.
 

Users who are viewing this thread

Back
Top Bottom