Creating the User Form

Figure 13-9 shows the finished UserForm for this example. For best results, start with a new workbook with only one worksheet in it. Then follow these steps:

1. Press Alt+F11 to activate the VBE.

2. In the Project window, select the workbook's project and choose Insert UserForm to add an empty UserForm.

3. The UserForm's Caption property will have its default value: UserForm1. Use the Properties window to change the UserForm's Caption property to Get Name and Sex. (If the Properties window isn't visible, press F4.)

4. Add a Label control and adjust the properties as follows:

; Open table as spreadsheet

Property

Value

Accelerator

N

Caption

Name:

TabIndex

0

5. Add a TextBox control and adjust the properties as follows:

> Open table as spreadsheet

Property

Value

Name

TextName

TabIndex

1

6. Add a Frame control and adjust the properties as follows:

; Open table as spreadsheet

Property

Value

Caption

Sex

TabIndex

2

7. Add an OptionButton control inside the Frame and adjust the properties as follows:

*> Open table as spreadsheet

Property

Value

Accelerator

M

Caption

Male

Name

OptionMale

TabIndex

0

8. Add another OptionButton control inside the Frame and adjust the properties as follows:

*> Open table as spreadsheet

Property

Value

Accelerator

F

Caption

Female

Name

OptionFemale

TabIndex

1

9. Add yet another OptionButton control inside the Frame and adjust the properties as follows:

> Open table as spreadsheet

Property

Value

Accelerator

U

Caption

Unknown

Name

OptionUnknown

TabIndex

2

Value

True

10. Add a CommandButton control outside the Frame and adjust the properties as follows:

> Open table as spreadsheet

Property

Value

Caption

OK

Default

True

Name

OKButton

TabIndex

3

11. Add another CommandButton control and adjust the properties as follow s:

> Open table as spreadsheet

Property

Value

Caption

Close

Cancel

True

Name

CloseButton

TabIndex

4

^ WitlGW* Vmrfi Dm - ^-IrmraNfl... al^n . bf^ .»M .IpM . Of*F«441 fit«FH 0 Ilk |0H Ulnr Im fc—rt OHfjj ► Imh Ud 1-, Vnfti +Hp - « >

I tilt"

Figure 13-9: This dialog box asks the user to enter a name and a sex.

Tip When you are creating several controls that are similar, you may find it easier to copy an existing control rather than create a new one. To copy a control, press Ctrl while you drag the control to make a new copy of it. Then adjust the properties on the copied control.

0 0

Post a comment