Button Events

Click and DblClick

Private Sub Button_Click()
Private Sub Button_DblClick()

The Click event is fired when the button is single clicked. This event is commonly used with check box or push button styles to process code. In the Click event handler, you would likely call the Recalculate method. In the Exec event handler, you would query the Check property to determine the state of the Button. The DblClick event is fired when the button is double-clicked, although not commonly used for button controls.

Error

Private Sub Button_Error(short Number, BSTR* Description, SCODE Scode,
  BSTR Source, BSTR HelpFile, long HelpContext, boolean* CancelDisplay
);

The Error event is fired when an error occurs, and can be used to create error handling that is more complex than a simple failure of the control. See the VBScript documentation from Microsoft for more information on the appropriate codes.

KeyDown, KeyPress, and KeyUp

Private Sub Button_KeyDown(KeyCode As Integer, Shift As Integer)
Private Sub Button_KeyUp(KeyCode As Integer, Shift As Integer)
Private Sub Button_KeyPress(KeyAscii As Integer)

The KeyDown, KeyPress, and KeyUp events are fired in sequence when a key is pressed and released. They are commonly used to intercept keystrokes received by a form or control. The KeyPress event is the most commonly handled.

Element

Description

KeyCode

An integer that represents the key code of the key that was pressed or released.

Shift

The state of [SHIFT], [CTRL], and [ALT].

KeyAscii

An integer value that represents a standard numeric ANSI key code.

MouseDown, MouseMove, and MouseUp

Private Sub Button_MouseDown(Button As Integer, Shift As Integer,
  x As OLE_XPOS_PIXELS, y As OLE_YPOS_PIXELS
)
Private Sub Button_MouseMove( Button As Integer, Shift As Integer,
  x As OLE_XPOS_PIXELS, y As OLE_YPOS_PIXELS
)
Private Sub Button_MouseUp(Button As Integer, Shift As Integer,
  x As OLE_XPOS_PIXELS, y As OLE_YPOS_PIXELS
)

The MouseDown event is fired when the user presses a mouse button. The MouseMove event is fired when the user moves the mouse over the control. The MouseUp event is fired when the user releases the mouse button.

Element

Description

Button

An integer value that identifies which mouse button caused the event.

Shift

The state of [SHIFT], [CTRL], and [ALT].

x,y

The horizontal or vertical position, in points, from the left or top edge of the form, Frame, or Page.

ReadyStateChange

Private Sub Button_ReadyStateChange()

The ReadyStateChange event is fired when a control transitions to the next ready state due to the amount of data received.

SelectionChange

Private Sub Button_SelectionChange()

The SelectionChange event is fired when the selection of the Radio-Button group changes.