创建一个表单,用户可以在其中输入报告的开始和结束日期 [英] Creating a form where user inputs start and end dates of a report

查看:22
本文介绍了创建一个表单,用户可以在其中输入报告的开始和结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 MS Access 2007.

I am working on MS Access 2007.

我正在尝试创建一个表单,用户将在其中输入 2 个日期 - 开始日期和结束日期.我希望这些日期成为报告的边界.

I am trying to create a form where the user will input 2 dates - a start date and an end date. I want these dates to become the boundaries of a report.

例如,如果用户输入 01/03/14 和 10/03/14,我希望 Access 创建这两个日期之间的数据(例如售价)报告.

For example if the user inputs 01/03/14 and 10/03/14, I want Access to create a report of the data (eg Selling Price) between these two dates.

我该怎么做?

推荐答案

有几种方法可以执行此操作.

There are a few ways to perform this.

在我个人看来,最简单、最直接的方法是创建一个表单,用户将在其中输入开始/结束日期,并使用查询获取报告所需的所有信息(包括您的日期参数),以及以您的查询为记录源的报告.

The easiest, and most straight forward, in my personal opinion, involve creating a form where the user(s) will be entering Start/End dates, using a query that captures all of the information necessary for your report (including your date parameters), and the report with your query as the recordsource.

创建一个包含 2 个文本框控件的表单:随意命名它们(例如 StartDateTxt、EndDateTxt)和一个按钮控件.

Create a form with 2 text box controls: Name them whatever you like (StartDateTxt, EndDateTxt, for example), and a button control.

现在,创建一个查询,检索此报告所需的所有正确信息.我知道你说的是售价,对于初学者来说.

Now, create a query, that retrieves all of the correct information you need for this report. I know you said selling price, for starters.

对于您想缩小搜索范围的日期字段,您需要将它们放在WHERE 子句或QBE 中的Criteria 字段中代码>.它可能看起来像:

For the date fields you want to narrow down your search by, you need to put them in the WHERE clause or the Criteria field in QBE. It might look something like:

[Forms]![YourFormName]![StartDateTxt] and [Forms]![YourFormName]![EndDateTxt]

注意:引用字段有时可能很棘手.

Note: Referencing fields can sometimes be tricky.

接下来,您需要创建报告.如果您是新手,可以使用位于以下位置的报告向导:创建 - 报告部分 - 报告向导.

Next, you need to create a report. If you're new to this, you can use the Report Wizard located at: Create - Reports section - Report Wizard.

您可以从第一个提示的下拉列表中选择您的查询,然后添加您想要/需要的字段.单击下一步:您可以在此处对报告中的出现顺序进行排序.单击下一步:然后您可以证明您的布局 - 如果您不熟悉这些差异,则可以尝试使用它们.单击下一步:选择要应用于报告的主题"(字体/颜色等).单击下一步:然后您可以预览报表或修改报表的设计.(实际上,您可以通过单击任一按钮并单击打印预览或设计视图来执行任一操作.)

You can select your query from the dropdown list on the first prompt, and add the fields you desire/need. Click next: Here you can sort your order of appearance on the report. Click next: Then you can justify your layout - if you aren't familiar with the differences, you can play around with them. Click next: Select a 'theme' to be applied to your report (font/colors, etc). Click next: Then you can either preview the report or Modify the report's design. (Really, you can do either, by clicking either button and clicking print preview or design view.)

如果您单击预览报告 - Access 应该会询问您基础查询所需的任何参数.

If you click on Preview the report - Access should ask you for any parameters your underlying query requires.

右键单击您的按钮控件.-> 属性 -> 事件 -> OnClick -> 单击该行最右侧的 [...] 图标.选择代码生成器.

Right click on your button control. -> Properties -> Event -> OnClick -> click the [...] icon to the very right of the row. Select code builder.

Private SubEnd Sub之间,你要写

DoCmd.OpenReport "YourReportName"

您还可以检查以确保您的报告尚未打开.

You can also check to make sure your report isn't already open.

Dim ReportName As String
ReportName = "YourReportName"

            If CurrentProject.AllReports(ReportName).IsLoaded Then
                DoCmd.Close acReport, ReportName
            End If

            DoCmd.OpenReport ReportName, acViewPreview

我希望这能帮助您/回答您的问题.

I hope this helps you/answers your question.

编辑:如果有人想通过澄清或其他替代方法对此进行编辑/添加,请随意.请告诉我.

Edit: If anyone wants to edit/add on to this either by means of clarification or another alternative approach, please feel free. Just let me know.

这篇关于创建一个表单,用户可以在其中输入报告的开始和结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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