OnKeyPress Property [Access 2003 VBA Language Reference]
Sets or returns the value of the On Key Press box in the Properties window of one of the objects in the Applies To list. Read/write String.
expression Required. An expression that returns one of the objects in the Applies To list.
This property is helpful for programmatically changing the action Microsoft Access takes when an event is triggered. For example, between event calls you may want to change an expression's parameters, or switch from an event procedure to an expression or macro, depending on the circumstances under which the event was triggered.
The KeyPress event occurs when a user presses and releases a key or key combination that corresponds to an ANSI code while a form or control has the focus. This event also occurs if you send an ANSI keystroke to a form or control by using the SendKeys action in a macro or the SendKeys statement in Visual Basic.
The OnKeyPress value will be one of the following, depending on the selection chosen in the Choose Builder window (accessed by clicking the Build button next to the On Key Press box in the object's Properties window):
- If Expression Builder is chosen, the value will be "=expression", where expression is the expression from the Expression Builder window.
- If Macro Builder is chosen, the value is the name of the macro.
- If Code Builder is chosen, the value will be "[Event Procedure]".
If the On Key Press box is blank, the property value is an empty string.
The following example prints the value of the OnKeyPress property in the Immediate window for the button named "OK" on the "Order Entry" form.
Debug.Print Forms("Order Entry").Controls("OK").OnKeyPress
Applies to | BoundObjectFrame Object | CheckBox Object | ComboBox Object | CommandButton Object | Form Object | ListBox Object | OptionButton Object | TabControl Collection | TextBox Object | ToggleButton Object