我有这个 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 https://msdn.microsoft.com/en-us/library/office/ff836416.aspx method.
数据库.OpenRecordset 方法 (DAO) https://msdn.microsoft.com/en-us/library/office/ff820966.aspx
如果在 Microsoft Access 工作区中打开 Recordset 并且未指定类型,则 OpenRecordset 将创建表类型 Recordset(如果可能)。如果指定链接表或查询,OpenRecordset 将创建动态集类型的 Recordset。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)