Page 273 - Excel Progamming Weekend Crash Course
P. 273

n540629 ch19.qxd  9/2/03  9:35 AM  Page 248




                248                                                         Saturday Evening

                  The next step is to add the required code to the form. This code is placed in event proce-
               dures and is executed automatically when the user takes certain actions (in this case, when
               the command buttons are clicked). You learn more about events and event procedures later;
               for now, however, follow the directions to complete the demonstration project.
                  With the user form still selected, click the View Code button in the Project window. The
               code-editing window for the user form opens. Note that there are two drop-down lists at the
               top of this window. You use these lists as follows:

                   The list on the left contains all the controls on the form, and an entry for the user
                   form itself, as shown in Figure 19-4. It also contains an entry (General). To edit code
                   for a control or for the form, select the item in this list.


















                    Figure 19-4 Selecting the object whose code you want to edit

                   The list on the right lists all of the available event procedures for the item selected
                   in the first list. Select the desired event, and the editor automatically enters the
                   outline of the event procedure. Select (Declarations) to enter/edit code outside of
                   any procedure.

                          If you double-click a control on the form during design or the form itself,
                          the code editing window opens and displays the default event procedure for
                   Tip    that control. The default event procedure — the one that the Microsoft peo-
                          ple think will be used most often — is the Click event for many controls.
                  To add the event code to the demonstration project, follow these steps:

                 1. In the left list in the editing window, select cmdClose.
                 2. The list on the right automatically selects the Click event because this is the most
                    commonly used event for the Command Button control. The outline of the event
                    procedure is entered in the window, as shown in Figure 19-5.
   268   269   270   271   272   273   274   275   276   277   278