Visual Basic Reference

Change Event

See Also    Example    Applies To

Indicates the contents of a control have changed. How and when this event occurs varies with the control:

  • ComboBox changes the text in the text box portion of the control. Occurs only if the Style property is set to 0 (Dropdown Combo) or 1 (Simple Combo) and the user changes the text or you change the Text property setting through code.

  • DirListBox changes the selected directory. Occurs when the user double-clicks a new directory or when you change the Path property setting through code.

  • DriveListBox changes the selected drive. Occurs when the user selects a new drive or when you change the Drive property setting through code.

  • HScrollBar and VScrollBar (horizontal and vertical scroll bars) move the scroll box portion of the scroll bar. Occurs when the user scrolls or when you change the Value property setting through code.

  • Label changes the contents of the Label. Occurs when a DDE link updates data or when you change the Caption property setting through code.

  • PictureBox changes the contents of the PictureBox. Occurs when a DDE link updates data or when you change the Picture property setting through code.

  • TextBox changes the contents of the text box. Occurs when a DDE link updates data, when a user changes the text, or when you change the Text property setting through code.


Private Subobject_Change([indexAsInteger])

The Change event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index An integer that uniquely identifies a control if it's in a control array


The Change event procedure can synchronize or coordinate data display among controls. For example, you can use a scroll bar's Change event procedure to update the scroll bar's Value property setting in a TextBox control. Or you can use a Change event procedure to display data and formulas in a work area and results in another area.

Change event procedures are also useful for updating properties in file-system controls (DirListBox, DriveListBox, and FileListBox). For example, you can update the Path property setting for a DirListBox control to reflect a change in a DriveListBox control's Drive property setting.

Note   A Change event procedure can sometimes cause a cascading event. This occurs when the control's Change event alters the control's contents, for example, by setting a property in code that determines the control's value, such as the Text property setting for a TextBox control. To prevent a cascading event:

  • If possible, avoid writing a Change event procedure for a control that alters that control's contents. If you do write such a procedure, be sure to set a flag that prevents further changes while the current change is in progress.

  • Avoid creating two or more controls whose Change event procedures affect each other, for example, two TextBox controls that update each other during their Change events.

  • Avoid using a MsgBox function or statement in this event for HScrollBar and VScrollBar controls.