Work with command buttons

Once you have created your command button, you can customize it to better fit your needs.

Move the command button

  1. Open a form, report, or data access page in Design view.
  2. Do one of the following:

    Move a control and its label together

    1. Click the control or its label.

      When you click either part of a compound control in forms and reports, Microsoft Access displays the move handles for both controls, as well as the sizing handles for the control that you clicked. On data access pages, when the control is selected, the label is not automatically selected. If you move the control, the label goes with it. But if you move the label, the control does not move.

    2. Move the pointer over the border (not the move handle) of either the control or its label. After the pointer changes to an open hand, you can drag the control or controls to a new position.

      Control in form or report showing cursor changed to an open hand

      1  Move handles of a control in a form or report.

      2  When the pointer changes to an open hand, you can drag the control.

      Control in data access page showing cursor changed to an open hand

      1  Move handle of a control in a data access page

      2  When the pointer changes to an open hand, you can drag the control.

    Move a control and its label separately

    In a data access page, you can't move a control separately from its label, but you can select the label and move it separately from the control.

    1. Click the control or its label.
    2. Do one of the following:
      • In a form or report, place the pointer over the move handle in the upper-left corner of the control or label, and the pointer changes to an upward-pointing hand.

      Cursor changed to an upward-pointing hand

      1  When the pointer changes to an upward-pointing hand, you can drag the control.

      • In a data access page, place the pointer on any edge of the label, and the pointer changes to an open hand.
    3. Drag the control or label to its new position.

    Notes   

    • The parts of a compound control remain related, even if you move the individual parts separately.
    • To move an attached label to another section without moving the control, you must use the Cut and Paste commands. In a form or report, if you move a label to another section, the label will no longer be related to the control.

    Move two or more controls at the same time

    1. Select the controls by holding down the SHIFT key as you click each control.
    2. Pass the pointer over the border (not the move handle) of any selected control until it turns into an open hand, and then drag the controls to a new position.

    Example of several controls selected at once

    1  Move handle

    2  When the pointer changes to an open hand, you can drag the controls.

    Move a control in front of or behind other controls

    • Click the control that you want to move, and then on the Format menu, click Send to Back or Bring to Front.

    Note   A list box or subform is always in front of other controls; you can't format a list box or subform so that it is behind another control.

Tips

Size the command button

Resize a control

  1. Open a form, report, or data access page in Design view.
  2. Select the control or controls that you want to resize. To select more than one control, hold down the SHIFT key and click each control, or drag a rectangle over the controls.
  3. Drag the sizing handles until the control is the size you want.

Example of move handles and sizing handles

1  Move handle

2  Sizing handles

If you select more than one control, all the controls change size as you drag the sizing handle of one control.

Note   In data access pages, you can't resize a drop-down list box vertically. The vertical size of the drop-down list box is based on the font setting of the data in the control.

Tip

If you want to make small adjustments to the size of a control in a form or report, you might find it easier to press SHIFT plus the appropriate arrow keys.

Size controls uniformly relative to each other on a form or report

  1. Open a form or report in Design view.
  2. Select the controls that you want to size by holding down the SHIFT key and clicking each control, or by dragging a rectangle over the controls.
  3. On the Format menu, point to Size, and then click one of the following commands:
    • To Tallest  Makes the controls as tall as the tallest selected control.
    • To Shortest  Makes the controls as short as the shortest selected control.
    • To Widest  Makes the controls as wide as the widest selected control.
    • To Narrowest  Makes the controls as narrow as the narrowest selected control.

Size controls uniformly relative to each other on a data access page

How you size controls relative to each other depends on whether you have Microsoft Internet Explorer 5.5 or Internet Explorer 5 installed.

Resize a control to fit its contents

You can resize a label, command button, image control, or unbound object frame to fit its contents. Also, if you increase the font size for a control, you can resize the control to accommodate the larger font.

  1. Open a form, report, or data access page in Design view.
  2. Select the control or controls that you want to resize.
  3. On the Format menu, point to Size, and then click To Fit.

Resize a control by using the grid

  1. Open a form, report, or data access page in Design view.
  2. If the grid isn't already displayed, on the View menu, click Grid.
  3. Select the controls that you want to resize.
  4. On the Format menu, point to Size, and then click To Grid.

Add a picture to the command button

Add a picture to a command button or a toggle button on a form

  1. Open a form in Design view.
  2. Click the command button or toggle button, and then click Properties on the toolbar to open its property sheet.
  3. Click the Format tab, and in the 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.

    Tip

    In Microsoft Paint, you can create a file with a picture and caption for a button. Draw the picture and caption on a background of any size, and then select only the portion that will fit on the button. On the Edit menu, click Copy To and specify a file name in the Copy To dialog box.

Add a picture to a command button on a data access page

  1. Open a data access page in Design view.

  2. Click the command button you want to add the picture to, and then click Properties on the toolbar.

  3. Click the Format tab, and in the BackgroundImage property box, specify the location of image you want to use in the following format:

    url("http://WebServerName/FileName")

  4. Do one of the following:

    • To specify that only one image appears on the button, set the BackgroundRepeat property to no-repeat.

    • To specify that copies of the image appear in a horizontal line on the button, set the BackgroundRepeat property to repeat-x.

    • To specify that copies of the image appear in a vertical line on the button, set the BackgroundRepeat property to repeat-y.

  5. Set the position of the image in the BackgroundPositionX and BackgroundPostionY property boxes.

Change the command button caption

  1. Open a form, report, or data access page in Design view.
  2. Click the label or button, and then select the label text or button text.

    Button with label text selected

  3. Type the new text.

See the event procedure behind the command button

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.

  1. In form Design view, right-click the command button created by the Command Button Wizard.
  2. On the shortcut menu, click Build Event.