Writing VBA Procedures to Respond to Form and Control Events

Before the user can accomplish specific tasks with a custom form, you must usually write several VBA procedures. As mentioned earlier, each form created in the Visual Basic Editor has a module for storing procedures used by that form.

Before displaying a custom form, you may want to set initial values for controls. To set the initial values, or default values, that the controls will have every time the form is displayed, write an Initialize event procedure for a UserForm.

The Initialize event occurs when the form is loaded but before it's shown on the screen. Suppose that you want the Info Survey form to appear with the following initial settings:

■ The Hardware button is selected in the Main Interest frame.

■ The list box below contains the items that correspond to the selected Hardware option button.

■ None of the Computer Type check boxes are selected.

■ The combo box below the Where Used label displays the first available item, and the user cannot add a new item to the combo box.

■ The text box next to the spin button displays the initial value of zero (0).

■ The image control displays a picture related to the selected Hardware or Software option button.

0 0

Post a comment