Creating the dialog box

Figure 18-1 shows the finished custom dialog box 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 empty workbook and choose InsertOUserForm.

An empty UserForm is added to the project.

3. Change the UserForm's Caption property to Get Name and Sex. If the Properties window isn't visible, press F4.

Figure 18-1:

This dialog box asks the user to enter a name and a sex.

Figure 18-1:

This dialog box asks the user to enter a name and a sex.

This dialog box has eight controls:

^ A Label. I modified the following properties for this control: Property Value Accelerator N Caption Name

TabIndex 0

A TextBox. I modified the following properties for this control: Property Value Name TextName

TabIndex 1

1 A Frame object. I modified the following properties for this control: Property Value Caption Sex TabIndex 2

i An OptionButton. I modified the following properties for this control: Property Value Accelerator M Caption Male

Name OptionMale

TabIndex 0

i Another OptionButton. I modified the following properties for this control:

Property Value Accelerator F Caption Female Name OptionFemale

TabIndex 1

i Another OptionButton. I modified the following properties for this control:

Property Value Accelerator U Caption Unknown

Name OptionUnknown

TabIndex 2 Value True i A CommandButton. I modified the following properties for this button: Property Value Caption OK Default True

Name OKButton

TabIndex 3

i Another CommandButton. I modified the following properties for this button:

Property

Caption

Cancel

Name

TabIndex

Value

Cancel

True

CancelButton 4

If you're following along on your computer (and you should be), take a few minutes to create this UserForm using the preceding information. Make sure to create the Frame object before adding the OptionButtons to it.

In some cases, you may find copying an existing control easier than creating a new one. To copy a control, press Ctrl while you drag the control.

If you prefer to cut to the chase, you can download the example from this book's Web site.

0 0

Post a comment