Changing Control Names

Before you begin to write procedures to control the form, you should assign your own names to the individual controls placed on the form. Although Visual Basic automatically assigns a default name to each control, these names are difficult to distinguish in a procedure that may reference objects of the same class that have almost identical names: OptionButton1, OptionButton2, and so on. Assigning meaningful names to the controls placed on your form makes VBA procedures referencing these controls much more readable.

To assign a new name to a control:

■ Click the appropriate control on the form.

■ Double-click the Name property in the Properties window.

Caution: Before you change the Name property, make sure that the title bar of the Properties window displays the correct type of the control. For example, to assign a new name to the frame control, click the frame control on the form. When the Properties window displays "Properties—Framel," double-click the Name property and type the new name in place of the highlighted default name.

Do not confuse the name of the control with the control's title (caption). For example, on the Info Survey form, the default name of the frame control is Framel, but the title of this control is Main Interest. The control title can be changed by setting a Caption property. While the control's caption allows the user to identify the purpose of the control and may suggest the type of data expected, it is the name of the control that will be used in the code of your VBA procedures to make things happen.

1. Assign names to the controls placed on the Info Survey form as shown in the following table:

Object Type Name Property

First option button optHard

Second option button optSoft

List box lboxSystems

Third option button optMale

Fourth option button optFemale

First check box chkIBM

Second check box chkNote

Third check box chkMac

Combo box cboxWhereUsed

Text box txtPercent

Spin button spPercent

First command button butOK

Second command button butCancel

Image picImage

0 0

Post a comment