Running code when pressing the * key

G

Guest

In the application I'm using, I enter several numbers in a subform, then
click a Next Button on the main form to move to the next record. The Next
Button's click event has the code shown below, and all works well:

DoCmd.GoToRecord , , acNext
Me!sfrmEnterValues.SetFocus

My boss has asked me to do a presentation over the next three days, and I've
just realized I have a problem. I've been given a numeric key pad to enter
data while at the lecturn, but it will be somewhat difficult to click the
Next button on the main keyboard. (it is out of reach and hard to see in the
bright lights) The numeric keypad has an asterisk key that I would like to
use to run the Next button's code shown above.

I'm very new to programming, so I'm hoping someone can tell me how to code
this.

grateful for any assistance
 
A

Allen Browne

If you are sure you will never need to use the star (e.g.for multiply), you
could use the KeyPress event procedure to move to the new record.

Cancel the keystroke:
KeyAscii = 0
to get rid of the star character.

Save the record:
RunCommand acCmdSaveRecord
That clears the other pending events.

Then call your button's code, e.g.:
Call Button1_Click
 
G

Guest

Allen - thank you for your timely advice. I'm very new to this. Would I
start with something like If KeyAscii = vbKeyMultiply then KeyAscii = 0
?
 
A

Allen Browne

Hmm: that doesn't look right. Perhaps that's a key scan code rather than the
ASCII character.

Create a test form, with 2 text boxe named (say) Text0 and Text2.
In the KeyPress event of Text0, show the number in the other text box:
Me.Text2 = KeyAscii
You can now see the number for any character.

You'll probably end up with something like this:
If KeyAscii = 42 Then
KeyAscii = 0
RunCommand acCmdSaveRecord
Call Button1_Click
End If
 
C

Charles GUELDRE

did you try the following (from Help in Access):
Assign an action or set of actions to a key
You can assign an action (action: The basic building block of a macro;
a self-contained instruction that can be combined with other actions to
automate tasks. This is sometimes called a command in other macro
languages.) or set of actions to a specific key or key combination by
creating an AutoKeys macro group (macro group: A collection of related
macros that are stored together under a single macro name. The collection is
often referred to simply as a macro.). When you press the key or key
combination, Microsoft Access carries out the action. If you assign an
action to a key combination that is already being used by Access (for
example, CTRL+C is the key combination for Copy), the action you assign this
key combination replaces the Access key assignment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top