问题
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