Home Access 2002 Buttons Add Command Buttons To A Form   |   Search MS Office A-Z   |   Search Web Pages/ Design A-Z

Add Command Buttons To A Form

You usually use a form in Access to enter new records into your database. Because data entry is an essential but routine exercise, you want to make your forms as efficient as possible.

One way to enhance form efficiency is to add command buttons. With a single click, a command button can execute a simple task. You can close a form; delete a record; run an external application, such as Microsoft Word; and perform many other tasks. The Command Button Wizard makes it easy to create buttons on your form to execute these and other operations.

You may be wondering why you should bother creating a button to close a form? There are indeed easy and fast alternatives for carrying out this simple chore. But when you’re performing many repetitive operations, a conveniently placed button that saves you just a little time here and there can add up to significant gains in productivity.

Command buttons can be slightly more sophisticated and perform several actions at once. Let’s say that, when you use a certain form, you find you often want to open a related report and print it. Ordinarily, you’d have to return to the Database Window, select the report, and issue the print command.

A command button, however, can automate the process and let you perform the task with one mouse click. In that sense, clicking a command button is like executing a simple macro that performs several operations in one fell swoop.

Let’s take a look at how to use the Command Button Wizard to add command buttons to a form. .

 Review A Form

Open the Northwind.mdb in the Samples subfolder of your Microsoft Office folder. Assuming you’ve made a copy (or have a backup) of the Northwind database, open the file. In the Database window, click Forms. Double-click the Customer Phone List to open it. If necessary, click the Maximize button in the upper-right corner of the window to maximize it.

Notice that the form contains phone numbers and other contact information for customers. You can find a specific customer quickly by clicking the first initial of his name in the bottom row of buttons.

Suppose you use the form often and would like a fast, convenient way to close it. You could add a command button to the button row that performs that operation.

 Create A Command Button

Click View to switch to Design View. First, let’s make the form a little wider so we have some room to add the button. Move the mouse pointer to right-edge of the form, which is at the 6-inch mark on the horizontal ruler. When the pointer changes to a double-arrow-with-bar, drag it to the 7-inch mark and release.

The toolbox should be in view. If it isn’t, choose View and then Toolbox. The Control Wizards button, which will usually be the second button on the first row, should be selected. (You can identify a button in the toolbox by holding the pointer over it and waiting a moment until its name is displayed.)

Click the Command Button tool, the third icon in the fourth row. Drag the pointer to the Form Footer. Position the crosshairs on the first dot in the first row after the 6-inch mark and click.

The Command Button Wizard opens. The types of actions are listed in the Categories section in the left; the various actions for each category are on the right. Press your down arrow key slowly to move from category to category and review the actions available in each.

To create a button to close a form, select Form Operations in the Categories section and Close Form in the Actions section. Click Next. You can choose to have text or a picture on your button. This is a personal choice and does not affect the action. The Picture radio button should be selected. Click the Stop Sign selection and note the display in the Sample section at left. Now click the Exit selection and view the display.

Click Next and then click Finish. Access creates the button on your form.

 Test The Button

It’s always a good idea to test your buttons after you create them. Click Save and then click View. At the bottom right of the form, click the button you just created to close the form. From the Database window, click Design to reopen the form in Design View.

 Modify The Button

Suppose you decide that you would prefer to have the stop sign on your button. You can easily change the icon using the button’s property sheet.

In the Form Footer, right-click the button you created and choose Properties. On the Format tab, click in the Picture property and click the three-dot button at its right. Use the scroll bar to move down the list and select Stop Sign. Click OK and close the property sheet. Click View to see the new icon on the button.

Click View again. The close button should still be selected. If you’d like to get rid of the button, press DELETE. Close the form and save your changes.