30.04.2017 Views

4523756273

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 18: UserForm Techniques and Tricks<br />

303<br />

✓ Enclose each set of OptionButtons in a Frame control. This approach<br />

is the easiest, and also makes the dialog box look more organized. It’s<br />

easier to add the Frame before adding the OptionButtons. You can, however,<br />

also drag existing OptionButtons into a Frame.<br />

✓ Make sure that each set of OptionButtons has a unique GroupName<br />

property (which you specify in the Properties box). If the OptionButtons<br />

are in a Frame, you don’t have to be concerned with the GroupName<br />

property.<br />

Figure 18-7:<br />

This dialog<br />

box<br />

contains<br />

three sets<br />

of Option<br />

Button<br />

controls.<br />

Only one OptionButton in a group can have a value of True. To specify a<br />

default option for a set of OptionButtons, just set the Value property for the<br />

default item to True. You can do this directly in the Properties box or by using<br />

VBA code:<br />

UserForm1.OptionButton1.Value = True<br />

This example is available at this book’s Web site. It also has code that displays<br />

the selected options when the user clicks OK.<br />

Using a SpinButton and a TextBox<br />

A SpinButton control lets the user specify a number by clicking arrows. This<br />

control consists only of arrows (no text), so you usually want a method to<br />

display the selected number. One option is to use a Label control, but this<br />

has a disadvantage: The user can’t type text in a Label. A better choice is to<br />

use a TextBox.<br />

A SpinButton control and TextBox control form a natural pair, and Excel<br />

uses them frequently. For example, check out Excel’s Page Setup dialog box<br />

for a few examples. Ideally, the SpinButton and its TextBox are always in<br />

sync: If the user clicks the SpinButton, the SpinButton’s value should appear

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!