在 MS Access VBA 中,如何使用参数调用存储的追加查询?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6232736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:22:45  来源:igfitidea点击:

In MS Access VBA, how do I call a stored append query with parameters?

ms-accessvbaparameters

提问by Isaac Moses

In my Access 2007 database, I've got an append query with parameters in it. How do I call this query from a VBA script?

在我的 Access 2007 数据库中,我有一个带有参数的附加查询。如何从 VBA 脚本调用此查询?

I realize that I could just generate the query text on the fly in the VBA code, but that's much more awkward.

我意识到我可以在 VBA 代码中动态生成查询文本,但这要尴尬得多。

回答by Isaac Moses

I got the following to work:

我得到了以下工作:

Dim db As DAO.Database
Dim qry As DAO.QueryDef

Set db = CurrentDb

Set qry= db.QueryDefs("NameOfMyStoredQuery")

qry.Parameters(0) = FirstParamValue
qry.Parameters(1) = SecondParamValue
qry.Parameters(2) = ThirdParamValue

qry.Execute