Click Event

Click Event

See Also         Example         Applies To        

The Click event occurs only if it has been defined for a control in the Script Editor.

The TabStrip and MultiPage controls do not support the Click event. However, individual the Page objects of the MultiPage control do support the click event.

ScrollBars and SpinButtons do not support the Click event but you can bind them to fields and use the CustomPropertyChange event.

The Click event occurs in one of two cases:

Syntax

Sub object_Click( )

The Click event syntax has these parts:

Part Description
object Required. A valid object.

Example:

Sub CommandButton1_Click()
    MsgBox "You just clicked my button! "
End Sub

Remarks

Of the two cases where the Click event occurs, the first case applies to the CommandButton, Frame, Image Label, and Page.

The second case applies to the CheckBox, ComboBox, ListBox, and ToggleButton. It also applies to an OptionButton when the value changes to True.

The following are examples of actions that initiate the Click event:

For some controls, the Click event occurs when the Value property changes. However, using the PropertyChange or CustomPropertyChange event is the preferred technique for detecting a new value for a property. The following are examples of actions that initiate the Click event due to assigning a new value to a control:

The Click event is not initiated when Value is set to Null.

Note Left-clicking changes the value of a control, thus it initiates the Click event. Right-clicking does not change the value of the control, so it does not initiate the Click event.

Also Note If you bind a ListBox, ComboBox, OptionButton, or CheckBox to a field, then the Click event does not fire. You need to use the PropertyChange or CustomPropertyChange event to detect the change via code.

Example:

Sub Item_PropertyChange(ByVal Name)
Set MyListBox = Item.GetInspector.ModifiedFormPages("Message").Controls("ListBox1")
Select Case Name
    Case "Mileage"
        Item.CC = MyListBox.Value
        Item.Subject = MyListBox.Value
    Case Else
End Select
End Sub