Recordsets are used to manipulate data in Access databases; they represent the records in tables or queries in a database. There are five types of DAO recordsets, with different properties, as described in the following sections. Specify the recordset type by using the appropriate constant for the type argument when creating a recordset, as in the following code:

Set rst = dbs.OpenRecordset(Name:="tblOrders", _ Type:=dbOpenDynaset)

Table 5.3 lists the named constants corresponding to the five recordset types (and their numeric equivalents). These named constants are used in VBA code; some dialects of Visual Basic, such as

VBScript (VBS), don't support named constants, so you need to use the numeric values instead, for example when writing Outlook VBS code or Windows Script Host (WSH) code.


DAO Recordset Type Named Arguments

Recordset Type

Named Constant Numeric Value


dbOpenTable 1


dbOpenDynaset 2


dbOpenSnapshot 4


dbOpenForwardOnly 8


dbOpenDynamic 16

If you don't specify a recordset type, DAO assumes first that you intend to create a table-type recordset, and if that is impossible, then a dynaset, then a snapshot, then a forward-only recordset. The table- and dynaset-type recordsets are the most commonly used types.

0 0

Post a comment