错误3061查询"损失"格式文本值 [英] Error 3061 Query "loses" form text value

查看:308
本文介绍了错误3061查询"损失"格式文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看着一批3061职位,但他们都在VB中查询。我试图运行在访问一个已经保存的查询,有使用窗体上的文本字段中的过滤器。因此,所有我试图做的只是得到一个记录从现有的查询。

I looked at a number of 3061 posts but they all have the query in VB. I am trying to run an already saved query in Access, that has a filter using a text field on a form. So all I am trying to do is just get a recordset from an existing query.

不知道相当如何解释发生了什么事情。但我有一个法师的形式持有的文本对象当前选定的日期。我有一个基于文本的对象值过滤结果的查询:

Not sure quite how to explain what's going on. But I have a Master form which holds the current selected date in a text object. I have a query that filters results based on the text object value:

  SELECT DISTINCT EmployeeName
    FROM dbo_Audits
   WHERE dbo_Audits.AuditDate = [Forms]![MasterForm]![ReportDate]

运行查询是好的,它拉选定日期,除非在特定的情况下。

Running the query is fine and it pulls for the selected date except in a specific circumstance.

如果我打开一个子窗体,并保持主表单仍然开放,但没有焦点,它仍然有效,即我可以运行查询,并将其拉员工的一天,有一个审核的名单。

If I open a subform, and keep the master form still open but not in focus, it still works i.e. I can run the query and it pulls the list of employees that had an audit that day.

但是,如果我点击子窗体上的一个按钮执行一个动作,把一个断点在OnClick事件,然后尝试运行该查询,它不返回任何结果。它的,因为它不承认,或者它失去的价值[表格]![MasterForm]![ReportDate],因此不返回任何结果。

But if I click a button on the subform to perform an action and put a breakpoint on the OnClick event, then try to run the query, it doesn't return any results. Its because it doesn't "recognize" or it's lost the value of "[Forms]![MasterForm]![ReportDate]" and therefore no results are returned.

奇怪的是,在断点处,我查询在中间窗口中的文本框的值,它仍然返回的日期。

Odd thing is, at the breakpoint, I query the text box value in the intermediate window and it still returns the date.

这是我所测试过的一种方式。但我真正想要做的是从该查询得到的记录,在后端编码,但遇到这种编码时:

That is one way I have tested it. But what I am really trying to do is get the recordset from this query, in the back end coding, but when it encounters this coding:

 strSQL = "SELECT * FROM " & strQueryName & " "
 Set rstNames = CurrentDb.OpenRecordset(strSQL)

在OpenRecordSet返回错误信息:

The OpenRecordSet returns the error message:

      3061 - Too Few Parameters.  Expected 1.

我穿上OpenRecordSet一个断点,并做了DCOUNT在strQueryName并获得的记录数的结果。因此,该查询样的工作。但不是当我通过访问运行该查询(而在断点处),而不是当它试图打开记录。

I put a breakpoint on the OpenRecordSet and do a DCount on the strQueryName and get a result of the number of records. So the query is kind of working. But not when I run the query through access (while on the breakpoint) and not when it tries to open the recordset.

任何想法,这是怎么回事,如何解决这一问题?

Any ideas what's going on and how to fix this?

推荐答案

由于 OpenRecordset 不解除引用 [表格]![MasterForm]![ ReportDate] ,并认为这是一个参数,打开保存的查询作为的QueryDef 对象,并给它的参数值访问希望。然后你可以使用 OpenRecordset 的QueryDef

Since OpenRecordset does not dereference [Forms]![MasterForm]![ReportDate], and thinks it's a parameter, open the the saved query as a QueryDef object and give it the parameter value Access wants. Then you can use OpenRecordset from the QueryDef.

Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs(strQueryName)
qdf.Parameters(0).Value = Eval(qdf.Parameters(0).Name)
Set rstNames = qdf.OpenRecordset()

这篇关于错误3061查询"损失"格式文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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