Share via


Connection.OpenRecordset Method

Access Developer Reference

Creates a new Recordset object and appends it to the Recordsets collection.

Syntax

expression.OpenRecordset(Name, Type, Options, LockEdit)

expression   A variable that represents a Connection object.

Parameters

Name Required/Optional Data Type Description
Name Required String The source of the records for the new Recordset. The source can be a table name, a query name, or an SQL statement that returns records. For table-type Recordset objects in Microsoft Access database engine databases, the source can only be a table name.
Type Optional Variant A RecordsetTypeEnum constant that indicates the type of Recordset to open.
Bb221075.vs_note(en-us,office.12).gif  Note
If you open a Recordset in a Microsoft Access workspace and you don't specify a type, OpenRecordset creates a table-type Recordset, if possible. If you specify a linked table or query, OpenRecordset creates a dynaset-type Recordset.
Bb221075.vs_note(en-us,office.12).gif  Note
If you open a Recordset in a Microsoft Access workspace and you don't specify a type, OpenRecordset creates a table-type Recordset, if possible. If you specify a linked table or query, OpenRecordset creates a dynaset-type Recordset.
Options Optional Variant A combination of RecordsetOptionEnum constants that specify characteristics of the new Recordset.
Bb221075.vs_note(en-us,office.12).gif  Note
The constants dbConsistent and dbInconsistent are mutually exclusive, and using both causes an error. Supplying a lockedits argument when options uses the dbReadOnly constant also causes an error.
Bb221075.vs_note(en-us,office.12).gif  Note
The constants dbConsistent and dbInconsistent are mutually exclusive, and using both causes an error. Supplying a lockedits argument when options uses the dbReadOnly constant also causes an error.
LockEdit Optional Variant A LockTypeEnum constant that determines the locking for the Recordset.
Bb221075.vs_note(en-us,office.12).gif  Note
You can use dbReadOnly in either the options argument or the lockedits argument, but not both. If you use it for both arguments, a run-time error occurs.
Bb221075.vs_note(en-us,office.12).gif  Note
You can use dbReadOnly in either the options argument or the lockedits argument, but not both. If you use it for both arguments, a run-time error occurs.

Return Value
Recordset

Remarks

Typically, if the user gets this error while updating a record, your code should refresh the contents of the fields and retrieve the newly modified values. If the error occurs while deleting a record, your code could display the new record data to the user and a message indicating that the data has recently changed. At this point, your code can request a confirmation that the user still wants to delete the record.

You should also use the dbSeeChanges constant if you open a Recordset in a Microsoft Access database engine-connected ODBC workspace against a Microsoft SQL Server 6.0 (or later) table that has an IDENTITY column, otherwise an error may result.

Opening more than one Recordset on an ODBC data source may fail because the connection is busy with a prior OpenRecordset call. One way around this is to fully populate the Recordset by using the MoveLast method as soon as the Recordset is opened.

Closing a Recordset with the Close method automatically deletes it from the Recordsets collection.

Bb221075.vs_note(en-us,office.12).gif  Note
If source refers to an SQL statement composed of a string concatenated with a non-integer value, and the system parameters specify a non-U.S. decimal character such as a comma (for example, strSQL = "PRICE > " & lngPrice, and lngPrice = 125,50), an error occurs when you try to open the Recordset. This is because during concatenation, the number will be converted to a string using your system's default decimal character, and SQL only accepts U.S. decimal characters.