The
btnStatus_Click
sub-procedure retrieves the current selections that
use the control’s
Value
property. It displays a message box containing essen-
tially the same information as the
OptionButton
example in the preceding
“Making choices with option buttons and frames” section.
Although this code performs essentially the same task as the
OptionButton
code, it requires far less code. In fact, this code
actually provides more input
choices than the
OptionButton
example.
Adding controls to the Toolbox
You might find that you need other controls in order to create your program.
Windows provides a wealth of controls that you can use. The Toolbox that
VBA provides has only a few essential controls in it — you can always add
more by using the following procedure:
1. Right-click anywhere on the Controls page of the Toolbox, and then
choose Additional Controls from the context menu that appears.
You see the
Additional Controls dialog box, shown in Figure 7-6.
2. Select the control that you want to add to your Toolbox by placing a
check mark next to its entry.
3. Click OK.
VBA adds the selected control to your Toolbox.
The Toolbox can get crowded after you add a few controls to it. You can
add pages to the Toolbox by right-clicking outside the existing pages and
then choosing New Page from the context menu that appears. Getting rid of
a page is as easy as selecting that page, right-clicking
outside the page area,
Figure 7-6:
Add
controls
to your
Toolbox by
using the
options
in this
dialog box.
172
Part II: Learning the Ropes
12_046500 ch07.qxp 12/5/06 5:35 PM Page 172
and then choosing Delete Page from the context menu that appears. It’s also
easy to move and rename pages by using context menu entries.
Using the Forms You Create
Forms are useful only if they’re usable. This means modifying the form and
control properties to provide a pleasant appearance. You should change
certain properties every time that you create a form to ensure that everyone
can use it easily. Arranging the content of
the form onscreen is important,
as is making sure that the form operates correctly. Finally, you need to know
how to handle events that the form generates to ensure that you see the
expected results.
Modifying the form and control properties
In previous sections of this chapter, you discovered properties that you can
change on your form or control to get specific results.
Whenever you select
the form or a control that it contains, the Properties window changes to
match the selection.
You might look at the enormous list of properties provided with the form and
controls and wonder how you can memorize them all. The fact is that you
don’t have to memorize any of them. To see what task a property performs,
highlight that property and then press F1. VBA provides property-specific help.
Some properties provide exceptional value from a user perspective. Always
define the
Accelerator
property for your controls.
This property lets some-
one use the keyboard, rather than the mouse, to access the control. It’s an
essential property if you want to make your program accessible to those with
special needs.
When you use a
Label
control to provide accelerator key access for a con-
trol that doesn’t
include a
Caption
property, make sure that the
TabIndex
property value for the
Label
is one less than the control that it references.
For example, if a
TextBox
has a
TabIndex
value of
5
, the associated
Label
should have a
TabIndex
value of
4
. Otherwise, the accelerator key doesn’t
work as anticipated.
Another
important property is
ControlTipText
. Type a description of the
control’s purpose in this property. When you hover the mouse over the con-
trol, VBA displays the text that you typed as balloon help. This kind of help is
a halfway point between the prompt that you type and the context-sensitive
help that your program should provide. It gives additional information with-
out opening the help file.
173
Do'stlaringiz bilan baham: