参数太少的OpenRecordset方法问题 [英] OpenRecordset Method Issue With Too few Parameters

查看:668
本文介绍了参数太少的OpenRecordset方法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个看似简单的问题使我已经停了三天.

This seemingly simple problem has me stopped dead in my tracks for three days now.

我的代码:

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("qryAutoOrder", dbOpenDynaset)

qryAutoOrder是一个选择查询,它本身运行良好且没有任何参数(除非查询构建器中的条件为标准).

qryAutoOrder is a select query which runs just fine by itself and has no parameters (unless criteria in the query builder count).

代码运行时,它挂在set rs =行上并引发此错误.

When the code runs it hangs on the set rs = line and throws this error.

运行时错误'3061':参数太少.预期为1.

Run-time error '3061': Too few parameters. Expected 1.

我想让代码为查询结果中的每条记录运行一个循环,以便我可以将数据追加到另一个现有数据库表中,但当前已将其注释掉.

There is more to the code where I would like it to run a loop for each record in the query results so that I can append data to another existing databases tables but it is currently commented out.

推荐答案

OpenRecordset不能解析查询中的表单引用([Forms]![completeRepair]![txtRepairID]).在这种情况下,它将被解释为您尚未提供值的参数.

OpenRecordset does not resolve the form reference ([Forms]![completeRepair]![txtRepairID]) in the query. In that situation, it is interpreted as a parameter for which you have not supplied a value.

因此,通过Eval(prm.Name) ...

Dim rs As DAO.Recordset
Dim db As DAO.database
Dim prm As DAO.Parameter
Dim qdf As DAO.QueryDef

'Set rs = CurrentDb.OpenRecordset("qryAutoOrder", dbOpenDynaset)
Set db = CurrentDb
Set qdf = db.QueryDefs("qryAutoOrder")
For Each prm In qdf.Parameters
    prm.value = Eval(prm.Name)
Next
Set rs = qdf.OpenRecordset(dbOpenDynaset)

实际上,您实际上不需要For循环.这就是我习惯养成的方式.但是您可以只给它一个参数值...

You don't actually need a For loop there; that's just the way I set these up by habit. But you could just give it the single parameter value instead ...

qdf.Parameters(0).Value = [Forms]![completeRepair]![txtRepairID]

这篇关于参数太少的OpenRecordset方法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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