每次运行查询时,在同一报表中显示查询结果 [英] Display results of query from a form in the same report each time the query is run

查看:57
本文介绍了每次运行查询时,在同一报表中显示查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个从表单运行的查询。执行查询时,将显示结果。我希望将这些结果放在格式化的报告中,如果需要可以打印并且不会显示在屏幕上。此外,一旦创建了格式化报告,我希望此后的每个查询的结果都使用相同的格式化报告进行打印。现在困难的部分,想在编码中包含VBA,该编码分配给指定在表单上执行查询的命令按钮,以生成格式化报告

解决方案

< blockquote> mcervenka1,


可能您不完全了解查询和报告之间的关系。


查询只需根据特定条件从数据库中收集和显示数据。报告仅使用查询结果。


因此,如果您有查询,则您的大部分工作都是为此帖子完成的。只需创建一个报告并将其记录源设置为您所描述的查询。将qurey中的字段添加到报表中,并根据需要格式化报表。保存报告后,无论何时运行报告,都将基于查询提取的最新数据。我希望这是有道理的。


你的困难部分实际上是容易的部分。只需使用 DoCmd.OpenReport [ReportName],acNormal 即可运行并打印报告。


可能会稍微多一些,但这是一般的想法。


我们很乐意引导您完成这个更具挑战性的方面......


有意义。请允许我试着澄清一下。我正在从表单运行查询。在表单和按钮中输入参数信息以执行查询。我在哪里添加你的编码?我正在使用宏'。请参阅附件包含:表单,属性表,嵌入式宏命令和查询





附加文件
查询表格Report.docx (136.1 KB,63 views)


我的第一个问题是,是否有必要在VBA中构建您的查询?


可以创建一个使用表单中值的查询。查询中的条件是 [Forms]![FormName]![TextBoxName]


有可能VBA创建查询定义,然后报告可以使用该定义,但它比我建议的更多涉及。


让我们知道你想要的方向。


-------

另外,作为旁注,我建议 使用宏,因为它们严重限制了Access的功能。即使是这个论坛上最聪明的专家,由于其固有的局限性,通常也不擅长使用宏。我不相信你可以通过使用宏来做你的建议(但我可能是错的)。坚持使用VBA,您可以更好地控制项目的各个方面。


I have created a query which is run from a form. When the query is executed the results are displayed. I would like to have those results in a formatted report that can be printed if desired and not displayed on the screen. In addition once the formatted report has been created, I would like for the result for every query thereafter to be printed using the same formatted report. Now the hard part, would like to include the VBA in the coding that is assigned to the command button assigned to execute the query on the form, to produce the formatted report

解决方案

mcervenka1,

It may be that you are not fully aware of how queries and reports are related to each other.

A query simply gathers and presents data from your database, based on certain criteria. A report merely uses the results of the query.

So, if you have your query, you have the majority of your work done for this post. Simply create a report and set its record source to the query you have described. Add the fields from the qurey onto your report and format the report as desired. Once you save the report, any time you run the report, it will be based on the most current data pulled by the query. I hope this makees sense.

Your "hard part" is actually the easy part. Simply use DoCmd.OpenReport [ReportName], acNormal to run and print the report.

There may be slightly more to it, but that is the general idea.

We will be glad to guide you through any more challenging aspects of this....


makes sense. Please allow me try to clarify. I am running the query from a form. Entering the parameter information into the form and the push button to execute the query. Where would I add your coding? I am using macro''s. Please see attachment containing: Form, Property Sheet, embedded macro commands, and query

Attached Files
Query Form Report.docx (136.1 KB, 63 views)


My first question would be, "Is it necessary to build your Query in the VBA?"

It is possible to create a query that uses the values from your Form. The Criteria in the query would be [Forms]![FormName]![TextBoxName].

It is possible to have the VBA create the Query Definition and then the Report can use that definition, but it is a bit more involved than what I have suggested.

Let us know the direction you want to go.

-------
Also, as a side note, I would recommend NOT using Macros, as they severely limit the capabilities of Access. Even the brightest experts on this forum are not usually very adept at using macros because of their inherent limitations. I do not believe you can do what you are suggesting by using macros (but I may be wrong). Stick to VBA and you have more control over all aspects of your project.


这篇关于每次运行查询时,在同一报表中显示查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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