访问 VBA Docmd.OpenQuery 可以 运行 更新查询但 Currentdb.Excecute 不能

Access VBA Docmd.OpenQuery Can Run an update query but Currentdb.Excecute Cannot

我创建了一个保存的更新查询,如下所示,它具有控制值和 IIf 功能。

UPDATE SYS_AAAA_AAAH 
SET SYS_AAAA_AAAH.AAK = AAA & " " & AAB & IIf(IsNull(AAC),"","(" & AAC & ")") & IIf(IsNull(AAF),""," not null") & " comment '" & AAH & "',"
WHERE (((SYS_AAAA_AAAH.AAO)=[forms]![frmAdmiTabl]![CombSAAO]));

DoCmd.OpenQuery 可以 运行 它而 Currentdb.Execute 给出错误消息 'too few parameters'。我创建了另一个保存的更新查询,没有来自控件或函数的输入并且 Currentdb.Execute 工作。我不想看到来自 Docmd.OpenQuery 的警告消息,也不想通过打开和关闭警告来搞乱。无论如何让 Currentdb.Execute 解决这个问题?

当你想用另一列的值和IIf功能更新某些记录的列时,最好使用DAO.recordset editupdate

  Dim Rs_AAAH As DAO.Recordset

    Set Rs_AAAH = CurrentDb.OpenRecordset("select * from Table where AAO='" & Me.CombSAAO.Value & "'", dbOpenDynaset)

    Rs_AAAH.MoveFirst

    Do Until Rs_AAAH.EOF

        With Rs_AAAH
            .Edit
            .Fields("AAK").Value = Rs_AAAH.Fields("AAA") & " " & Rs_AAAH.Fields("AAB") & IIf(IsNull(Rs_AAAH.Fields("AAC")), "", "(" & Rs_AAAH.Fields("AAC") & ")") & IIf(IsNull(Rs_AAAH.Fields("AAF")), "", " not null") & " comment '" & Rs_AAAH.Fields("AAH") & "',"
            .Update
        End With

        Rs_AAAH.MoveNext
    Loop

    Rs_AAAH.Close
    Set Rs_AAAH = Nothing