vba - Access VBA错误 "operation not supported for this type of object"

标签 vba ms-access

我有这个 vba 代码,但我不明白为什么它返回错误
me.ID 存储为字符串顺便说一句

Private Sub ID_AfterUpdate()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Me.ID = UCase(Me.ID)
      Set db = CurrentDb
    Set rs = db.OpenRecordset("Products")   
    rs.FindFirst ("[SKU] =""" & Me.ID & """") //this is the one giving error
    If Not rs.NoMatch Then
        MsgBox ("SKU Existed")
        Me.ID.Value = Null
        Me.Next.SetFocus //just for the sake of moving to this field then
        Me.ID.SetFocus  //to this field coz sometimes it won't go straight to
    End If

    rs.Close
    Set rs = Nothing
    Set db = Nothing End Sub

any idea where I got this wrong ?

最佳答案

db.OpenRecordset("<a local Table>")

将打开Table类型的记录集,.FindFirst等对此无效。

使用dbOpenDynaset或使用.Seek方法。

Database.OpenRecordset Method (DAO)

If you open a Recordset in a Microsoft Access workspace and you don't specify a type, OpenRecordset creates a table-type Recordset, if possible. If you specify a linked table or query, OpenRecordset creates a dynaset-type Recordset.

关于vba - Access VBA错误 "operation not supported for this type of object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51283348/

相关文章:

java - 使用 Grails 连接到 MS Access 数据库时使用的方言

sql - MS Access 中的多个(左、交叉?)JOIN

excel - 字典、集合和数组的比较

excel - VBA 嵌套循环提前退出

vba - Excel VBA For-Loop 仅在 Debug模式下运行

vba - 更改代码,使其不会填充更多单元格,只需替换为更改

java - ms access编码问题(与jsp连接)

excel - 在Excel中,我可以使用超链接来运行vba宏吗?

excel - 如何在 VBA 中连接字符串?

c# - 来自 Access ODBC 驱动程序的无效日期时间格式异常