如何通过VBA在Query中传递参数值 [英] How to pass Parameter Value in Query via VBA

查看:115
本文介绍了如何通过VBA在Query中传递参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个保存的查询(q_StdDegReqAll),它有一个参数(WHERE StdDegReq.StdDegReqId = lngStdDegReqId)。我想在vba中将值传递给此参数。我有以下代码:

展开 | 选择 | Wrap | 行号

解决方案

@ bullfrog83


是。


qd1.Parameters( lngStdDegReqId )= lngStdDegReqId


将lngStdDegReqId传递给自己?其中是lngStdDegReqId定义的值

对不起。它是在例程的开头定义的,其中传递一个值:

Public Sub procEvaluateDegReq(lngStdDegReqId As Long)


这是一个棘手的领域。 Recordset中的参数是暂时的。它们不会被您在Recordset中访问的任何QueryDef保存。


您的第5行(我假设是失败的那个)只会设置参数供我们使用 QD1 。随后打开QueryDef的调用将不会引用 qd1 中的参数。这有意义吗?


I have a saved query (q_StdDegReqAll) that has one parameter (WHERE StdDegReq.StdDegReqId = lngStdDegReqId). I want to pass a value into this parameter in vba. I have the following code:

Expand|Select|Wrap|Line Numbers

解决方案

@bullfrog83
Yes.

qd1.Parameters(lngStdDegReqId) = lngStdDegReqId

Passing lngStdDegReqId unto itself? where is lngStdDegReqId defined value


Sorry. It''s defined at the beginning of the routine where a value is passed into it:

Public Sub procEvaluateDegReq(lngStdDegReqId As Long)


This is a tricky area. Parameters in a Recordset are transitory. They do not get saved with any QueryDef you may be accessing in your Recordset.

Your line #5 (I assume to be the one that fails) would only set the parameter for use by qd1. The subsequent call to open the QueryDef would not have any reference to the parameter in qd1. Does that make sense?


这篇关于如何通过VBA在Query中传递参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆