简体   繁体   English

访问:“参数太少。”

[英]Access: “Too few parameters.”

I know this is a redundant question but could not find a similar scenario to mine. 我知道这是一个多余的问题,但找不到与我类似的情况。

I have a stored query which, when executed, picks values from the filters on an opened form and display results. 我有一个存储的查询,该查询在执行时会从打开的表单上的过滤器中选择值并显示结果。 All works. 所有作品。

Here is how the query is called: 这是查询的调用方式:

cmd.CommandType = adCmdStoredProc
cmd.CommandText = "qry"
Dim rsReport As New ADODB.Recordset
rsReport.CursorType = adOpenKeyset
rsReport.CursorLocation = adUseClient
rsReport.Open cmd

I am trying to use the same query from VBA to create Excel files which can be downloaded or emailed and I am getting a "Too few parameters" error now (while the form is still open). 我正在尝试使用来自VBA的相同查询来创建可以下载或通过电子邮件发送的Excel文件,并且现在(在表单仍处于打开状态)出现“参数过多”错误。 Can anyone set me in the right direction why this is happening please? 有人能为我设定正确方向的原因吗?

When executing a query using VBA, you can't reference open forms. 使用VBA执行查询时,无法引用打开的表单。 You need to explicitly state all parameters. 您需要明确声明所有参数。

If you're executing the query using DoCmd.RunQuery , you can set parameters using DoCmd.SetParameter . 如果使用DoCmd.RunQuery执行查询,则可以使用DoCmd.SetParameter设置参数。

If you're executing the query using QueryDef.Execute , you can set parameters using the QueryDef.Parameters collection. 如果使用QueryDef.Execute执行查询,则可以使用QueryDef.Parameters集合设置参数。

If you're executing the query using an ADODB.Command , you can set parameters by appending parameters to the Command.Parameters collection, in the following way: 如果使用ADODB.Command执行查询,则可以通过以下方式将参数附加到Command.Parameters集合来设置参数:

Command.Parameters.Append Command.CreateParameter ("MyParameterName", adInteger, adParamInput) where adInteger is the type. Command.Parameters.Append Command.CreateParameter ("MyParameterName", adInteger, adParamInput) ,其中adInteger是类型。 After that, you still need to set the parameter to a value by setting Command.Parameters("MyParameterName").Value = MyValue 之后,您仍然需要通过设置Command.Parameters("MyParameterName").Value = MyValue来将参数设置为一个值Command.Parameters("MyParameterName").Value = MyValue

Also see this question for info on ADODB parameters. 另请参阅此问题以获取有关ADODB参数的信息。 They are a bit more tricky. 他们比较棘手。

All parameters need to be filled in before executing the query. 在执行查询之前,需要填写所有参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM