DoCmd Object.
The GoToControl method carries out the GoToControl action in Visual Basic. For more information on how the action and its argument work, see the action topic.
DoCmd.GoToControl controlname
The GoToControl method uses the following arguments.
Argument |
Description |
controlname |
A string expression that is the name of a control on the active form or datasheet |
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 ControlCtl = Forms!Form1!Field3.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.
DoCmd Object, GoToControl Action, GoToPage Method (DoCmd Object), GoToRecord Method, SelectObject Method, SetFocus Method.
This example uses the GoToControl method to move the focus to the EmployeeID field.
DoCmd.GoToControl "EmployeeID"