access VBA error “operation not supported for this type of object”

江枫思渺然 提交于 2019-12-25 03:50:15

问题


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


回答1:


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

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

Either use dbOpenDynaset or use the .Seek method.

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.



来源:https://stackoverflow.com/questions/51283348/access-vba-error-operation-not-supported-for-this-type-of-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!