如何在 Microsoft Access 中通过 VBA 设置 INSERT SQL 查询的参数值? [英] How can one set parameter values of an INSERT SQL query through VBA in Microsoft Access?
问题描述
我是 Access 的新手,我来自 C#、SQL Server &.网.有一个项目来了,我必须完成一些部分.
I am new to Access and I am coming from C#, SQL Server & .Net. There is a project that has come my way and I have to complete some parts.
场景可以描述为:
- 带有子表单的 Access 表单
- 作为上述子表单数据源的 Access 查询,带有两个参数,显示为:
Parametername1 String(255),Parametername2 String(255)
. - VBA 代码模块
我的计划是在我的 VBA 代码模块的过程中设置上述查询参数的值.我相信这应该刷新我的子表单,因为查询是子表单的数据源.
My plan is to set the values of the above mentioned query parameters within a procedure in my VBA code module. I believe this should refresh my subform as the query is the datasource for the subform.
问题是我不知道如何实施这个计划.
The problem is I don't know how to implement this plan.
我想使用查询,因为我不想用内联 SQL 弄乱我的 VBA 代码.
I want to use a query because I don't want to mess up my VBA Code with inline SQL.
我使用的是 Access 2010.
I am using Access 2010.
推荐答案
我正好有这个问题,我想使用相同的存储"更新查询,但从两种不同的形式执行它,所以想将参数传递给查询在运行时.这是我发现的(在另一个论坛中)完全符合我的要求:
I had exactly this question, I wanted to use the same 'stored' update query but execute it from two different forms so wanted to pass the parameter to the query at run-time. This is what I found (in another forum) that does exactly what I want:
With CurrentDb.QueryDefs("qry_YourQuery")
.Parameters("yourParam") = yourVBAvar
.Execute
End With
这篇关于如何在 Microsoft Access 中通过 VBA 设置 INSERT SQL 查询的参数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!