访问VBA错误“此类型的对象不支持操作"; [英] access VBA error "operation not supported for this type of object"

查看:202
本文介绍了访问VBA错误“此类型的对象不支持操作";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this vba code and I don't understand why it return error
me.ID is stored as string btw

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

推荐答案

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

将打开一个类型为Table的记录集,该记录集的.FindFirst等无效.

will open a recordset of type Table, for which .FindFirst etc. are not valid.

使用dbOpenDynaset或使用 .Seek 方法.

Either use dbOpenDynaset or use the .Seek method.

Database.OpenRecordset方法(DAO)

如果您在Microsoft Access工作区中打开记录集,但未指定类型,则OpenRecordset会创建表类型的Recordset(如果可能).如果指定链接表或查询,则OpenRecordset会创建动态集类型的Recordset.

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错误“此类型的对象不支持操作";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆