- Open a form or a data access page in Design view.
- Make sure the Control Wizards tool in the toolbox is pressed in.
- In the toolbox, click the Command Button tool.
- On the form or data access page, click where you want to place the command button.
- Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.
Create or modify a command button without a wizard
- Open a form or a data access page in Design view.
- Make sure the Control Wizards tool in the toolbox is not pressed in. This turns off the wizard.
- In the toolbox, click the Command Button tool .
- On the form or data access page, click where you want to place the command button.
- Make sure that the command button is selected, and then click Properties on the toolbar to open the command button's property sheet.
- In the OnClick property box on a form, enter the name of the macro or event procedure that you want to run when the button is clicked, or click the Build button to use the Macro Builder or Code Builder. On a data access page, you can attach code written in either JScript or Microsoft Visual Basic Scripting Edition (VBScript) to a command button by using the Microsoft Script Editor.
- Do one of the following:
To display text on a command button on a data access page: Type the text in command button's Value property box.
To display text on a command button on a form: Type the text in the command button's Caption property box.
To display a picture on a command button on a form: In the command button's Picture property box, type the path and file name for a .bmp, .ico, or .dib file. If you're not sure of the path or file name, click the Build button to open the Picture Builder.
On a form, to Create or modify a command button that runs a macro, drag the macro from the Database window to form Design view.
- Open a form in Design view.
- Click the command button, and then click Properties on the toolbar to open the command button's property sheet.
- In the Cancel property box, click Yes.
When a command button's Cancel property is set to Yes and the form is the active form, you can choose the command button by clicking it, pressing the ESC key, or pressing ENTER when the command button has the focus. When the Cancel property is set to Yes for one command button, it's automatically set to No for all other command buttons on the form. Only one button can be the default on a form.
To have a Cancel button cancel all the actions that have taken place in a form or dialog box, you need to write a macro or event procedure and attach it to the OnClick property of the button.
For a form that allows irreversible operations, such as deletions, it's a good idea to make the Cancel button the default command button. To do this, set both the Cancel property and the Default property to Yes.
See an event procedure created by the Command Button Wizard
The following procedure describes how to display an event procedure created by the Command Button Wizard on a form. In a data access page, you have to create the event procedure yourself.
- In form Design view, right-click the command button created by the Command Button Wizard.
- On the shortcut menu, click Build Event.