GoToRecord Method

Applies To

DoCmd object.

Description

The GoToRecord method carries out the GoToRecord action in Visual Basic. For more information on how the action and its arguments work, see the action topic.

Syntax

DoCmd.GoToRecord [objecttype, objectname][, record][, offset]

The GoToRecord method has the following arguments.

Argument

Description

objecttype

One of the following intrinsic constants:

acActiveDataObject (default)
acDataForm
acDataQuery
acDataTable

objectname

A string expression that's the valid name of an object of the type selected by the objecttype argument.

record

One of the following intrinsic constants:

acFirst
acGoTo
acLast
acNewRec
acNext (default)
acPrevious

If you leave this argument blank, the default constant (acNext) is assumed.

offset

A numeric expression that represents the number of records to move forward or backward if you specify acNext or acPrevious for the record argument, or the record to move to if you specify acGoTo for the record argument. The expression must result in a valid record number.


Remarks

If you leave the objecttype and objectname arguments blank (the default constant, acActiveDataObject, is assumed for objecttype), the active object is assumed.

You can leave an optional argument blank in the middle of the syntax, but you must include the argument's comma. If you leave one or more trailing arguments blank, don't use a comma following the last argument you specify.

See Also

DoCmd object, GoToControl method, GoToPage method (DoCmd object), GoToRecord action, SelectObject method.

Example

The following example uses the GoToRecord method to make the seventh record in the form Employees current:

DoCmd.GoToRecord acDataForm, "Employees", acGoTo, 7