Navigate between controls, records, and form pages programmatically

Microsoft Office Access 2003

  1. To create a macro, click Macros Button image under Objects, and then click the New button on the Database window toolbar.
  2. Do one of the following:
    • To move the focus to a specific control or field in the current record, click GoToControl in the action list of a blank action row, and then set the Control Name argument to the name of the control to which you want to move.

    • To make a specific record the current record, click GoToRecord in the action list of a blank action row, and then set the arguments.

    • To move the focus in the active form to the first control on a specific form page, click GoToPage in the action list of a blank action row, and then set the arguments.

  3. Click Save Button image.
  4. To test, run the macro by clicking Run Button image on the toolbar.
  5. Open the form in Design view.
  6. Open the property sheet for the form, select the event property that you will use as a trigger and set it to the name of the macro.

For example, if a macro containing the GoToControl action is located in the OnCurrent event for the form, moving from one record to another will move the focus to the control.

ShowUse Visual Basic code

  1. To open the event procedure for the appropriate event, open the form in Design view.
  2. Display the property sheet for the form or control on the form and then click the Event tab.
  3. Click the event property for the event that you want to trigger the procedure.

    For example, to respond to a mouse click on a command button, open the button's OnClick event procedure.

  4. Click Build Button image next to the property box to display the Choose Builder dialog box.
  5. Double-click Code Builder to display the event procedure window.
  6. Do one of the following:
    • To move the focus to a specific control or field in the current record, carry out the GoToControl method in the procedure, setting the Control Name argument to the name of the control to which you want to move.
    • To make a specific record the current record or to create a new record, use the GoToRecord method to carry out the GoToRecord action in the procedure.
    • To move the focus in the active form to the first control on a specific form page, use the GoToPage method to carry out the GoToPage action in the procedure.

  7. To test, run the procedure by opening the form in Form view and performing the event that triggers the move.

For example, if the procedure is located in the event procedure for a command button, click the command button to observe the focus move to the control, record, or form page.

ShowTip

You can also use Microsoft Visual Basic for Applications to locate or move between records by using a Recordset object and the Seek method or any of the Move or Find methods.