C.4. OpenRecordset Constants

There are a variety of constants you'll use when writing VBA code. The following tables list just a few of the constants you might use when opening a DAO recordset.

NOTE

A runtime error occurs if you attempt to use dbOpenTable in the following Microsoft Jet workspace situations:

  • When the recordset is based on a QueryDef.

  • When the Type argument is set to dbOpenSnapshot.

  • When the Source argument refers to an SQL statement or TableDef that refers to a linked-table.

The following table lists the constants that can be specified for the Type argument.

ConstantDescription
DbOpenTableReturns an editable dataset consisting of records from a single local table only. Cannot be used with linked tables (Microsoft Jet workspaces only)
dbOpenDynamicReturns an editable dataset consisting of pointers to records in a table or query. Can be used on multiple remote tables (ODBCDirect workspaces only)
dbOpenDynasetReturns an editable dataset consisting of pointers to records in a table or query. Can be used on multiple local and linked tables (Microsoft Jet workspaces only)
dbOpenSnapshotReturns a read-only dataset consisting of a copy of records in a table or query. Can be used on multiple local and linked tables (Microsoft Jet workspaces only)
dbOpenForwardOnlyReturns an editable dataset consisting of records in a table. Use this option when you only need to move through the dataset in one pass and in one direction—forward (Microsoft Jet workspaces only)

The following table lists the constants that can be specified for the Options argument.

NOTE

The dblnconsistent and dbConsistent constants are mutually exclusive. Similarly you cannot supply a LockEdits argument on a recordset whose Options argument is set to dbReadOnly. If you attempt to do so, a runtime error occurs.

ConstantDescription
dbAppendOnlySignifies that you can add new records, but not edit or delete them (Microsoft Jet dynaset recordsets only)
dbSQLPassThroughSignifies that the SQL statement will be passed directly to a Microsoft Jet-connected ODBC data source for processing (Microsoft Jet snapshot recordsets only)
dbSeeChangesTriggers a runtime error if another user attempts to change data that you're currently editing (Microsoft Jet dynaset recordsets only)
dbDenyWriteLocks all the underlying tables so other users can only view the data. They cannot add, edit, or delete records while the lock is in place (Microsoft Jet recordsets only).
DbDenyReadCompletely locks all the underlying tables so other users cannot even view the data (Microsoft Jet table recordsets only).
dbForwardOnlyCreates a forward-only recordset (Microsoft Jet snapshot recordsets only). This option is provided for backward compatibility only, and you should use the dbOpenForwardOnly constant in the Type argument instead of this option.
DbReadOnlyCreates a read-only recordset, preventing users from making changes to the data (Microsoft Jet only).

You can use dbReadOnly in either the Options argument or the LockEdits argument, but not both. If you attempt to do so, a runtime error occurs.

This option is provided for backward compatibility only, and you should use the dbReadOnly constant in the LockEdits argument instead of this option.
dbRunAsyncRuns an asynchronous query (ODBCDirect workspaces only). This allows your code to keep running while the query is loading. You can use the StillExecuting property to determine if the query has completed.
dbExecDirectExecutes the query without first calling the SQLPrepare ODBC API function (ODBCDirect workspaces only). Only use this option when not opening a recordset based on a parameter query.
dbInconsistentAllows inconsistent updates (Microsoft Jet dynaset and snapshot recordsets only). An inconsistent update is one in which you can update all the columns in a multi-table recordset unless referential integrity rules prevent it.
dbConsistentAllows only consistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only). A consistent update is one in which you can only perform updates that result in a consistent view of the data. For example, you cannot update the many side of a relationship unless a matching record exists in the one side.

The following table lists the constants that can be specified for the LockEdits argument.

NOTE

You cannot supply a LockEdits argument on a recordset whose Options argument is set to dbReadOnly. If you attempt to do so, a runtime error occurs.

ConstantDescription
DbReadOnlyCreates a read-only recordset, preventing users from making changes to the data (This is the default setting for ODBCDirect workspaces). You can use dbReadOnly in either the Options argument or the LockEdits argument, but not both. If you attempt to do so, a runtime error occurs. Setting dbReadOnly in the Options argument is provided for backward compatibility only. You should use it in the LockEdits argument instead.
dbPessimisticUses pessimistic locking for changes made to the recordset in a multi-user environment. Pessimistic locking is where the entire data page that contains the record you're editing is locked (made unavailable to other users) as soon as you issue the Edit method, and remains locked until you issue the Update method (this is the default setting for Microsoft Jet workspaces).
DbOptimisticUses optimistic locking for changes made to the recordset in a multi-user environment. Optimistic locking is where the entire data page that contains the record you're editing is locked (made unavailable to other users) as soon as you issue the Update method, and remains locked until the data is written to the table (this is the default setting for Microsoft Jet workspaces). You use optimistic locking when manipulating ODBC databases or when the LockEdits property is set to False.
dbOptimisticValueUses optimistic concurrency based on row values (ODBCDirect workspaces only)
dbOptimisticBatchEnables batch optimistic updating (ODBCDirect workspaces only)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.0.240