Search code examples
ms-accessvbadao

When opening a RecordSet in Access VBA, if the type is dbOpenSnapshot, does it make the option dbReadOnly redundant?


In Access VBA, when opening a recordset as a snapshot, does it make the read-only option redundant? At first this seemed to be true, since a snapshot is essentially read-only already, but there always seems to be caveats.

Example:

Dim acc      as Access.Application
Dim db       as DAO.Database
Dim rs       as DAO.Recordset
Dim sqltext  as String

sqltext = "SELECT * FROM SOMESOURCE"

Set rs = db.OpenRecordset(sqltext, dbOpenSnapshot, dbReadOnly)

'Because the type is dbOpenSnapshot, does dbReadOnly become redundant?

Solution

  • Check the recordset's Updatable property. This one prints False.

    sqltext = "SELECT * FROM TABLE_01"
    Set db = CurrentDb
    Set rs = db.OpenRecordset(sqltext, dbOpenSnapshot)
    Debug.Print rs.Updatable
    

    So, yes, dbOpenSnapshot as the recordset Type option gives you a read-only recordset.