Creating a Recordset Variable

The OpenRecordset method is the basic method of creating a Recordset object variable. To use it, you first declare a variable of type Recordset object, and then set the variable to the object returned by the OpenRecordset method.

The OpenRecordset method is available from Database, TableDef, QueryDef and existing Recordset objects. For ODBCDirect workspaces, the OpenRecordset method is available from the Connection, Database, and QueryDef objects. The syntax of the OpenRecordset method for Database and Connection objects is:

Set recordset = object.OpenRecordset (source [, type [, options [, lockedits]]])

The syntax of the OpenRecordset method for all other types of objects is:

Set recordset = object.OpenRecordset ([type [, options [, lockedits]]])

The recordset argument is the name of the new Recordset object.

The object argument is the object from which you’re creating the new Recordset object. Microsoft Jet uses the source argument only for Recordset objects created from Database or Connection objects.

The source argument is an existing TableDef or QueryDef object in the database or a valid record-returning SQL query or statement. For TableDef, QueryDef, and Recordset objects, the object itself is automatically used as the source.

The type argument is an intrinsic constant that specifies the kind of Recordset object you want to create. The available type constants are:

If you open a Recordset object in a Microsoft Jet workspace and you don’t specify a type, OpenRecordset creates a table-type Recordset object, if possible. If you specify a linked table or query, OpenRecordset creates a dynaset-type Recordset object. In an ODBCDirect workspace, the default setting is dbOpenForwardOnly.

With the options argument of the OpenRecordset method, you can specify a number of other features for a Recordset object by using the following constants:

Note When you don’t use the options argument, you must specify 0 for it.

With the lockedits argument of the OpenRecordset method, you can specify locking options for a Recordset object by using the following constants:

See Also For more information about the dbOptimisticValue and dbOptimisticBatch constants, see Chapter 9, “Developing Client/Server Applications.” For more information about ODBCDirect, see Chapter 8, “Accessing External Data,” and Chapter 9, “Developing Client/Server Applications.”