In this chapter -
Adding a user form (custom dialog box) to your project -
Changing the look and behavior of the form -
Inserting, selecting, and manipulating form controls -
Understanding and working with the various form controls, from command buttons to check boxes -
Displaying and closing forms and getting the form results VBA procedures are only as useful as they are convenient . There isn't much point in creating a procedure that saves you (or your users) a few keystrokes if you (or they) have to expend a lot of time and energy hunting down a routine. Shortcut keys are true time-savers, but some applications (such as Excel) have only a limited supply to dole out (and our brains can memorize only so many Ctrl+ key combinations). Instead, you need to give some thought to the type of user interface you want to create for your VBA application. The interface includes not only the design of the documents, but also three other factors that let the user interact with the model: dialog boxes, menus, and toolbars. Although you certainly can give the user access to the application's built-in dialogs, menus, and toolbars, you'll find that you often need to create your own interface elements from scratch. This chapter starts you off by showing you how to use VBA's Microsoft Forms feature to create custom dialog boxes and input forms. Chapter 14, "Creating Custom Menus and Toolbars," shows you how to set up custom menus and toolbars . The InputBox function you learned about in Chapter 12, "Interacting with the User," works fine if you need just a single item of information, but what if you need four or five? Or, what if you want the user to choose from a list of items? In some cases, you can use the application's built-in dialog boxes (which I also discussed in Chapter 12), but these might not have the exact controls you need, or they might have controls to which you don't want the user to have access. | In VBA, dialog boxes are called user forms or just forms , for short. (A VBA form is a close cousin to the form objects that are used for data entry in Microsoft Access.) Since the term "form" is used in the Visual Basic Editor, I'll use that term throughout the rest of this chapter. Just remember, however, that a form is nothing but a dialog box that you create yourself. | The solution is to build your own dialog boxes. You can add as many controls as you need (including list boxes, option buttons, and check boxes), and your procedures will have complete access to all the results. Best of all, the Visual Basic Editor makes constructing even the most sophisticated dialog boxes as easy as clicking and dragging the mouse pointer. The next few sections show you how to create dialog boxes and integrate them into your applications. |