Change Event

See Also2IW4ZYK              Example5ZZEK5>Low

Applies To

Combo box1YZXFF6, directory list boxO9U5A0, drive list box5WJO0PW, horizontal scroll bar1JSJOS7, label3MNIZ8D, picture box31MYIWX, text boxYPYZDG, vertical scroll bar1JSJOS7.


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

         Combo boxchanges the text in the text box portion of the control.  Occurs only if the Style1L09GO8 property is 0 (Dropdown Combo) or 1 (Simple Combo) and the user changes the text or you change the Text14TWSRU property from code.

         Directory list boxchanges the selected directory.  Occurs when the user double-clicks a new directory or when you change the PathBKGP79 property from code.

         Drive list boxchanges the selected drive.  Occurs when the user selects a new drive or when you change the DriveYLV8AS property from code.

         Horizontal and vertical scroll barmoves the scroll box portion of the scroll bar.  Occurs when the user scrolls or when you change the Value5OIC88B property from code.

         Labelchanges the contents of the label.  Occurs when a DDE link updates data or when you change the CaptionF6ZZXB property from code.

         Picture boxchanges the contents of the picture box.  Occurs when a DDE link updates data or when you change the Picture4GBE5Q property from code.

         Text boxchanges the contents of the text box.  Occurs when the user changes the text or when you change the Text property from code.



Sub ctlname_Change (Index As Integer)


The argument Index uniquely identifies a control if it is in a control array8G7Y0UU.  A Change procedure can synchronize or coordinate data display among controls.  For example, you can use a scroll bar's Change procedure to update the scroll bar's Value property setting in a text box.  Or you might use a Change procedure to display data and formulas in a work area and results in another area.

Change procedures are also useful for updating properties in file-system controls.  For example, you can update the Path property for a directory list box to reflect a change in a drive list box's Drive property.


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

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

         Avoid creating two or more controls whose Change procedures affect each otherfor example, two text boxes that update each other.

         Also avoid using a MsgBox function or statement in this event for horizontal or vertical scroll bars.


See Also


KeyDown, KeyUp EventsRI06O6

KeyPress EventPFFDUA

LinkTopic PropertyEVWV3S

LostFocus Event2ZXQDAR

PathChange Event3811T7

PatternChange Event2JU7UW9


Programmer's Guide:

Chapter 3, "Creating and Using Controls"

Change Event Example

The example displays the numeric setting of a horizontal scroll bar's Value property in a text box. To try this example, create a form with a text box and a horizontal scroll bar (set Min = 0, Max = 1000, LargeChange = 100, and SmallChange = 1).  To try this example, paste the code into the Declarations section of a form that contains a horizontal scroll bar and a text box.  Then press F5 and click the horizontal scroll bar.

Sub Form_Load ()

   HScroll1.Min = 0                      ' Set Minimum.

   HScroll1.Max = 1000                   ' Set Maximum.

   HScroll1.LargeChange = 100            ' Set LargeChange.

   HScroll1.SmallChange = 1              ' Set SmallChange.

End Sub


Sub HScroll1_Change ()

   Text1.Text = HScroll1.Value

End Sub