Displaying a Custom Form

Each UserForm has a Show method that allows you to display the form to the user. In the example below, you will prepare the DoSurvey procedure. Recall that in the previous section you already assigned this procedure to the Survey button placed in the Info Survey worksheet.

1. In the Visual Basic Editor window select the CustomForms (Chap10.xls) project in the Project Explorer window and choose Insert | Module.

2. In the Properties Window, change the new module's name to ShowSurvey.

3. Enter the following procedure to display the custom form:

Sub DoSurvey()

InfoSurvey.Show End Sub

Notice that the Show method is preceded by the name of the form object as it appears in the Forms folder (InfoSurvey).

4. Save the changes made to Chap10.xls.

5. Switch to the Microsoft Excel window and click the Survey button. The Info Survey form appears.

Note: If an error message appears after you click the Survey button, you have not assigned the required macro to this button as instructed in step 6 in the previous section. To correct this problem, click OK in response to the message. Right-click the Survey button and choose Assign Macro from the shortcut menu. Click the DoSurvey macro name in the list box, and click OK. Now click the Survey button to display the form.

6. Close the Info Survey form by clicking the Close button (x) in the top right-hand corner of the form.

0 0

Post a comment