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

1

5

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?
Jaguarundi answered 8/8, 2018 at 18:30 Comment(0)
O
6

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.

Overflow answered 8/8, 2018 at 18:42 Comment(1)
The .Updateable property is influenced by a huge number of things, such as the content of the query, the presence of a primary key, and if the table is linked. However, dbOpenSnapshot is never updateable according to MSDN: Snapshot-type Recordset— a static copy of a set of records that you can use to find data or generate reports. A snapshot-type Recordset object can contain fields from one or more tables in a database but can't be updated. This type corresponds to an ODBC static cursor.Uranalysis

© 2022 - 2024 — McMap. All rights reserved.