我有这个 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
最佳答案
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/