Page 223 - Excel Data Analysis
P. 223

11 537547 Ch10.qxd  3/4/03  12:03 PM  Page 209






                                                                                           FORM CONTROLS 10


                                                The Click event occurs when the user clicks a control
                                                or a value in a control. For most controls, you can write
                                                a procedure to handle the Click event by placing the
                                                event name after the control name. All event-handling
                                                procedures require an underscore character between the
                                                control name and the event name.

                                                Example:
                                                Sub CommandButton1_Click()
                                                To capture the Click event to determine the page or tab
                                                selected with a MultiPage or TabStrip control, the
                                                procedure also includes an index parameter value that
                                                specifies the index to the page or tab.

                                                Example:
                                                Sub MultiPage1_Click(1)
                                                With the MultiPage and TabStrip controls, you must create a
                                                separate procedure to handle the selection of each page or
                                                tab by using the corresponding index value.
                                                Aside from an actual click of a control with the mouse, a
                                                Click event also occurs when you press Enter and a
                                                control is selected, when you press the accelerator key
                                                that corresponds to the control, or when you press the
                                                spacebar and a CommandButton is selected.




























                     ■ The code window for the   ■ Excel creates a subroutine   Á Type UserSelection =   ‡ Type Unload and follow
                     UserForm appears.         called CommandButton1_   ListBox1.Value, replacing   it with the name of the
                                               Click() in the code      UserSelection with the    UserForm.
                                               window.                  name of the global variable
                                                                        used to capture user input.          CONTINUED

                                                                                                                     209
   218   219   220   221   222   223   224   225   226   227   228