本文介绍了在 VBA 中附加查询以获取不采用 WHERE 参数的 microsoft access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能:

    Dim db As DAO.Database
    Dim strInsert As String

Set db = CurrentDb

strInsert = "INSERT INTO items_affected_Table(CR_Id, VerOld, Equipment_Serial, Document_No, Description, Version) SELECT Items_affected_Table.CR_Id, Items_affected_Table.Version, Items_affected_Table.Equipment_Serial, Items_affected_Table.Document_No, Items_affected_Table.Description, Items_affected_Table.VerNext FROM Items_affected_Table WHERE (((Items_affected_Table.CR_Id)=[Forms]![CR form-unapproved]![CR_ID]) AND ((Items_affected_Table.Version)=[Forms]![CR form-unapproved]![Version]))"

db.Execute strInsert, dbFailOnError

它给出了错误参数太少.预期为 2"

It gives the error "too few parameters. Expected 2"

如果我将表单引用更改为实际数字,则追加查询有效:

If I change the form references to actual numbers the append query works:

    strInsert = "INSERT INTO items_affected_Table(CR_Id, VerOld, Equipment_Serial, Document_No, Description, Version) SELECT Items_affected_Table.CR_Id, Items_affected_Table.Version, Items_affected_Table.Equipment_Serial, Items_affected_Table.Document_No, Items_affected_Table.Description, Items_affected_Table.VerNext FROM Items_affected_Table WHERE (((Items_affected_Table.CR_Id)=8) AND ((Items_affected_Table.Version)=0))"

我错过了什么?

谢谢

推荐答案

连接变量引用:

strInsert = "INSERT INTO items_affected_Table(CR_Id, VerOld, Equipment_Serial, Document_No, Description, Version) " & _
             "SELECT CR_Id, Version, Equipment_Serial, Document_No, Description, VerNext " & _
             "FROM Items_affected_Table " & _
             "WHERE CR_Id=" & [Forms]![CR form-unapproved]![CR_ID] & " AND Version=" & [Forms]![CR form-unapproved]![Version]

这篇关于在 VBA 中附加查询以获取不采用 WHERE 参数的 microsoft access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 00:28