DoCmd.GoToRecord Method

Access Developer Reference

The GoToRecord method carries out the GoToRecord action in Visual Basic.

Syntax

expression.GoToRecord(ObjectType, ObjectName, Record, Offset)

expression   A variable that represents a DoCmd object.

Parameters

Name Required/Optional Data Type Description
ObjectType Optional AcDataObjectType A AcDataObjectType constant that specifies the type of object that contains the record you want to make current.
ObjectName Optional Variant A string expression that's the valid name of an object of the type selected by the objecttype argument.
Record Optional AcRecord A AcRecord constant that specifies the record to make the current record. The default value is acNext.
Offset Optional Variant 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

You can use the GoToRecord method to make the specified record the current record in an open table, form, or query result set.

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

You can use the GoToRecord method to make a record on a hidden form the current record if you specify the hidden form in the objecttype and objectname arguments.

Example

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

Visual Basic for Applications
  DoCmd.GoToRecord acDataForm, "Employees", acGoTo, 7