GoToControl Method
Applies To
DoCmd object.
Description
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.
Syntax
DoCmd.GoToControl controlname
The GoToControl method has the following argument.
Argument | Description |
|
controlname | A string expression that's the name of a control on the active form or datasheet. |
Remarks
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.
See Also
GoToControl action, GoToPage method (DoCmd object), GoToRecord method, SelectObject method, SetFocus method.
Example
The following example uses the GoToControl method to move the focus to the EmployeeID field:
DoCmd.GoToControl "EmployeeID"