Create Hotkey to Open Form?

C

croy

How do I create a hotkey to open a form?

In one control on a form, I'd like the "+" key on the
numerical keypad to open a certain form, or cause the
OnClick event to run.

MS Access 2002.
 
J

John Smith

Use the KeyPress event of the control:

Private Sub SomeControl_KeyPress(KeyAscii As Integer)
If KeyAscii = 43 Then
DoCmd.OpenForm "Some Form"
KeyAscii = 0 ' Stop the + from going to the control
End If
End Sub

Plus whatever other code you need.

HTH
John
##################################
Don't Print - Save trees
 
C

croy

Use the KeyPress event of the control:

Private Sub SomeControl_KeyPress(KeyAscii As Integer)
If KeyAscii = 43 Then
DoCmd.OpenForm "Some Form"
KeyAscii = 0 ' Stop the + from going to the control
End If
End Sub

Plus whatever other code you need.


Thanks John. That's a huge help, especially the comments in
the code.

If there is already form-opening code for the OnClick event
for this control, is it better to call the OnClick event, or
use separate code, like above (assuming that it's even
possible to call another event's code)?
 
J

John Smith

Personally I try to avoid having more than one piece of code doing the same
thing so I would call the existing code. If you don't it tends to trip you up
later when you change one call but forget about the other one!

Just call it by name, something like:

ControlName_Click

John
##################################
Don't Print - Save trees
 
Top