Adding Controls to a User Form

To add controls to a UserForm, use the Toolbox. (The VBE does not have menu commands that add controls.) If the Toolbox is not displayed, choose View ^ Toolbox. Figure 13-2 shows the Toolbox.


Controls |

Figure 13-2: Use the Toolbox to add controls to a UserForm.

Just click the Toolbox button that corresponds to the control that you want to add, and then click inside the dialog box to create the control (using its default size). Or, you can click the control and then drag in the dialog box to specify the dimensions for the control.

When you add a new control, it is assigned a name that combines the control type with the numeric sequence for that type of control. For example, if you add a CommandButton control to an empty UserForm, it is named CommandButtonl. If you then add a second CommandButton control, it is named CommandButton2.

It's a good idea to rename all the controls that you will be manipulating with your VBA code. Doing so lets you refer to meaningful names (such as ProductListBox) rather than generic names (such as ListBoxl). To change the name of a control, use the Properties window in the VBA. Just select the object and enter a new name.

0 0

Post a comment