如何通过表单收集输入并传递到 Access 中的报告查询

发布于 2024-09-26 11:58:32 字数 921 浏览 0 评论 0原文

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

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

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

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

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

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

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. 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.

  2. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

束缚m 2024-10-03 11:58:32

好吧,

问题应该是你想要的逻辑。为什么需要一个调用表单的报告?为什么不使用一个表格来填充参数然后调用报告呢?

您可以按以下方式执行您的要求:

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

  2. 创建一个查询,检索报告的数据,在条件字段中引用表单中的参数(在示例中,<代码>[Forms]![Form1]![Param1]和[Forms]![Form1]![Param2])。另外,右键单击查询生成器的空白区域并选择“参数”。使用正确的信息告知所有参数(包含整个字符串 [Forms]![Form1]![Param1][Forms]![Form1]![Param2])数据类型。我们将此查询称为 Query1

  3. 根据 Query1 创建报告。我们将此报告称为 Report1

  4. 返回 Form1,创建一个按钮(使用向导,更快)来调用 Report1。

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

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

Well,

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. Create a form containing the fields corresponding to your desired parameters (Eg two textboxes called Param1 and Param2, in a form called Form1)

  2. 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

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

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

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文