Recordset.FindFirst method: why DOES it work with some of my Table-type recordsets?

时间:2015-08-06 13:52:46

标签: vba ms-access dao recordset

I was trying to use the Recordset.FindFirst method with DAO recordsets, in Access VBA, when I came across the error:

Error 3251: "Operation is not supported for this type of object."

After some brief investigation on the MSDN, I discovered that the method only works on dynaset-type or snapshot-type recordsets. I changed my code from this:

Set rs2 = db.OpenRecordset("table_name")
rs2.FindFirst [search criteria]

to this:

Set rs2 = db.OpenRecordset("table_name", dbOpenDynaset)
rs2.FindFirst [search criteria]

and all was working fine.


However, I have another database where I have been using FindFirst on table-type recordsets without error.

Set rs = db.OpenRecordset("tblUsers")
rs.FindFirst [search criteria]

My questions are

  1. Why this works in one database and not another, and
  2. If it would be advisable to change the code to use dbOpenDynaset type recordsets instead?

1 个答案:

答案 0 :(得分:2)

当您对查询或附加表执行OpenRecordset()时,Access默认为动态集类型(dbOpenDynaset)。

当你在本地表上使用OpenRecordset()时,它默认为表类型(dbOpenTable。)