GoToControl Method

Microsoft Access Visual Basic

action in Visual Basic.

expression.GoToControl(ControlName)

expression    Required. An expression that returns one of the objects in the Applies To list.

ControlName   Required Variant. A string expression that's the name of a control on the active form or datasheet.

Remarks

For more information on how the action and its argument work, see the action topic.

Use only the name of the control for the controlname argument, not the full syntax.

You can also use a variable declared as a Control data type for this argument.

Dim ctl As Control
Set ctl = Forms!Form1!Field3
DoCmd.GoToControl ctl.Name
		

You can also use the SetFocus method to move the focus to a control on a form or any of its subforms, or to a field in an open table, query, or form datasheet. This is the preferred method for moving the focus in Visual Basic, especially to controls on subforms and nested subforms, because you can use the full syntax to specify the control you want to move to.

Example

The following example uses the GoToControl method to move the focus to the EmployeeID field:

DoCmd.GoToControl "EmployeeID"