Creating a Simple Form

To begin designing a UserForm, click Insert, UserForm. A blank UserForm appears (see Figure 31-20) in place of the Code window (if showing) with the Toolbox window floating somewhere near it (see Figure 31-21). At the same time, the information in the Properties window changes to show properties for the new UserForm.

Note For the remainder of this section, UserForms are simply referred to as forms. k_*

ra o

Figure 31-20. A new UserForm window is the visual counterpart to a blank Code window.

Figure 31-21. Use the Toolbox to place visual components on your UserForm. You can use Tools, Additional Controls to place more "tools" in the Toolbox.

Follow these steps to change some of the default properties of the form:

1 In the Properties window, change the value for the Name field from UserForml to frmWelcome.

This changes the name of the form in the Project Explorer and is how you refer to the form, when necessary. Also, if you export it, frmWelcome.frm will be the filename of the form.

2 Change the value for the Caption field from UserForml to Welcome!. This is what appears in the title bar of the form when it is running.

3 Click the Font field and then use the Browse button to change the base font for the form from 8 point Tahoma to 10 point Arial (see Figure 31-22).

Although changing the font in the form doesn't have any visible effect, any controls you add to the form will use the font you specified as their default font. Changing the font now is quicker and easier than changing it for each control individually later.

Controls

Controls w

Name

Caption

Browse button Font

Name

Caption

Browse button Font

Figure 31-22. Start designing your UserForm by changing certain properties.

Now that you've created a form and modified some of its properties, the next task is to add controls. Follow these steps to add two buttons, a label, and a text box:

TextBox

Label

Command-Button

In the Toolbox window, click the TextBox button and then draw a rectangle on the form.

In the Properties window, change the value for the Name field from TextBox1 to txtName.

In the Toolbox window, click the Label button and then draw a rectangle just above the text box.

In the Properties window, change the value for the Name field from Label1 to lblName. Change the value for the Caption field from Label1 to Enter your name:. In the Toolbox window, click the CommandButton button, draw a rectangle to the right of the label and the text box and then click the CommandButton button again to draw another button just below the first.

Click the first button, change the value for Name from CommandButton1 to cmdOK, and then change the value for Caption from CommandButton1 to OK. Click the second button, and give it the name cmdCancel and the caption Cancel. Adjust the position of the controls and the size of the form (see Figure 31-23).

Figure 31-23. This is what the completed frmWelcome should look like after the controls have been positioned and the form sized appropriately.

Label

Command-Button

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment