访问对象424

时间:2017-06-13 01:57:16

标签: ms-access access-vba ms-access-2016

我正在运行一个表达式来遍历记录集,并且每个记录中的字符串在第二个表上运行更新查询。基于LIKE匹配,它更新字段以创建关系。我遇到运行时错误问题' 424' CurrentDb.Execute所需的对象。

表: 交易(要更新的主表) TransactionType(类型或类别的关系表) TransSet(要设置的字符串和事务类型列表)

Private Sub Toggle1_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset   
Set db = CurrentDb Set rst = db.OpenRecordset("TransSet")   
Do Until rst.EOF

CurrentDb.Execute ("UPDATE Transactions SET Transactions.TransactionType =" & (TransSet.TransTypeSet) & " WHERE ((Transactions.TransactionText1) Like * " &   (TransSet.TransIdent) & "*))")


rst.MoveNext Loop   
rst.Close Set rst = Nothing

End Sub

2 个答案:

答案 0 :(得分:1)

引用记录集对象,而不是记录集所基于的表或查询。 需要文本类型字段参数的撇号分隔符。

CurrentDb.Execute ("UPDATE Transactions SET TransactionType ='" & rst!TransTypeSet & "'" & _  
" WHERE TransactionText1 Like '*" & rst!TransIdent & "*'")

答案 1 :(得分:1)

谢谢 - 我也意识到了我的错误并修复了代码。我还更改了表名,以免与保留字混淆。

Private Sub Toggle1_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("Select * FROM TransSet")

Do Until rst.EOF


CurrentDb.Execute ("UPDATE Trans SET trans.TransactionType =" & (rst!TransTypeSet) & " WHERE ((Trans.TransactionText1) Like '*" & (rst!TransIdent) & "*');")

' MsgBox ("UPDATE Trans SET trans.TransactionType =" & (rst!TransTypeSet) &     " WHERE ((Trans.TransactionText1) Like '*" & (rst!TransIdent) & "*');")


   rst.MoveNext
Loop

rst.Close
Set rst = Nothing

End Sub