如何通过表单收集输入并传递到 Access 中的报告查询 [英] How to collect input via a form and pass to report query in Access

查看:29
本文介绍了如何通过表单收集输入并传递到 Access 中的报告查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Access 2003 MDB,我想在其中显示一个小表单,供用户输入两个参数开始日期"和结束日期".感谢另一位 Stack Overflow 用户(Kevin Ross"),我学会了如何将表单控件直接嵌入到我想要显示的报表所使用的查询中.

I have an Access 2003 MDB where I would like to present a small form for the user to input two parameters "Start Date" and "End Date". Thanks to another Stack Overflow user ("Kevin Ross"), I learned how to embed the form control directly in the query that is used by the report I would like to display.

SELECT q1.CasesAssigned, q2.WarningsIssued  
FROM 
    (SELECT COUNT(*) AS CasesAssigned 
    FROM vwCaseDetail 
    WHERE DateAssigned Between [Forms]![frmReporting]![txtStartDate] 
        AND [Forms]![frmReporting]![txtEndDate]) as q1,  
    (SELECT COUNT(*) AS WarningsIssued 
    FROM vwWarningDetail 
    WHERE DateIssued Between [Forms]![frmReporting]![txtStartDate] 
        AND [Forms]![frmReporting]![txtEndDate]) as q2

我尝试了两种不同的方式来打开报告并传递用户输入:

I have tried two different ways to open the report and pass the users input:

  1. 在用户输入参数后,我调用 DoCmd.OpenReport "myReport", acViewPreview.这里的问题是报告打开和关闭的速度太快了,我什至都没有看到.理想情况下,我想关闭输入集合表单,然后打开报告.

  1. After the user enters parameters I call DoCmd.OpenReport "myReport", acViewPreview. The problem here is that the reports opens and close so fast I never even see it. Ideally I would like to close the input collection form and then open the report.

Report_Open 事件中,我有代码可以打开收集用户输入的表单.输入集合表单打开,但是报告仍然提示我输入两个参数.该报告似乎没有从输入收集表单中收集参数.

Inside the Report_Open event I have code that opens the form that collect the users input. The input collection form opens, however I still get prompted by the report to enter in the two parameters. The report does not seem to be gathering the parameters from the input collection form.

关于将表单上收集的数据传递到报告的正确方法有什么建议吗?谢谢.

Any suggestions on the proper way to pass data collected on a form to a report? Thank you.

推荐答案

嗯,

问题应该是你想要什么的逻辑.为什么要调用表单的报告?为什么不用一个表格来满足参数然后调用报告?

The problem should be the logic of what your wantig. Why do you want a report calling a form? Why not a form in wich you fulfill the parameters then call the report?

您可以通过这种方式执行您的要求:

You can perform your requisites in this way:

  1. 创建一个包含与所需参数对应的字段的表单(例如两个名为 Param1 和 Param2 的文本框,在一个名为 Form1 的表单中)

  1. Create a form containing the fields corresponding to your desired parameters (Eg two textboxes called Param1 and Param2, in a form called Form1)

创建一个查询来检索报告的数据,在条件字段中引用表单中的参数(在示例中,[Forms]![Form1]![Param1][Forms]![Form1]![Param2]).此外,右键单击查询构建器的空白区域并选择参数".用正确的字符串通知所有参数(用整个字符串 [Forms]![Form1]![Param1][Forms]![Form1]![Param2]数据类型.我们将此查询称为 Query1

Create a query that retrieves the data for your report, referencing, in the conditions field, the parameters in the form (In the example, [Forms]![Form1]![Param1] and [Forms]![Form1]![Param2]). Also, right clik on a empty space of query builder and select "parameters". Inform all the parameters (with the entire strings [Forms]![Form1]![Param1] and [Forms]![Form1]![Param2]) with the correct data type. Let's call this query Query1

基于 Query1 创建报告.让我们将此报告称为 Report1

Create a report based on Query1. Lets call this report as Report1

返回 Form1,创建一个按钮(使用向导,速度更快)用于调用 Report1.

Back to Form1, create a button (use the Wizard, its faster) for calling Report1.

执行 Form1,在运行时用所需的参数填充文本框,然后单击按钮.确保您的表中有与查询对应的数据.

Execute the Form1, in runtime fill the textboxes with the desired parameters then click the button. Make sure that you have data in your tables wich corresponds the Query.

在应用程序的其他部分,您直接调用 Report1,而是调用将管理 Report1 查询和显示的 Form1.

In the other parts of your application, instead you call Report1 directly, call the Form1 that will manage Report1 querying and showing.

这篇关于如何通过表单收集输入并传递到 Access 中的报告查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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