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

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

问题描述



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



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

我该如何做?

解决方案

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



根据我个人的观点,最简单最直接的方法是创建用户将输入开始/结束日期的表单,使用捕获报告所需的所有信息(包括日期参数)的查询以及查询作为记录源的报告。



表单



创建一个带有2个文本框控件的窗体:将它们命名为任何你喜欢的内容(例如StartDateTxt,EndDateTxt)和一个按钮控制。





查询



现在,创建一个查询,该查询检索所有您需要为此报告提供的正确信息。我知道你说的是卖价格,对于初学者来说。



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

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

注意:引用字段有时可以会很棘手

报告



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



您可以从下拉列表中选择您的查询第一个提示,并添加您想要/需要的字段。点击下一步:您可以在此处对报告中的外观排序进行排序。点击下一步:然后你可以证明你的布局 - 如果你不熟悉这些差异,你可以和他们一起玩。点击下一步:选择一个主题应用于您的报告(字体/颜色等)。点击下一步:然后,您可以预览报告或修改报告的设计。 (真的,你可以通过点击任一按钮并点击打印预览或设计视图。)



如果您点击预览报告 - Access应该询问您您的基础查询需要的参数。

返回表单。



右键单击您的按钮控件。 - >属性 - >事件 - >点击 - >点击行右边的 [...] 图标。选择代码构建器。



VBA



中间 Private Sub End Sub ,您将写入

  DoCmd.OpenReportYourReportName

您也可以检查以确保您的报告尚未打开。

  Dim ReportName As String 
ReportName =YourReportName

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

DoCmd.OpenReport ReportName,acViewPreview

我希望这可以帮助您/回答您的问题。
$ b 编辑:如果有人想要通过澄清或其他替代方法来编辑/添加此内容,请放心。请让我知道。


I am working on MS Access 2007.

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.

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.

How can I do this?

解决方案

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.

Form

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

Query

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

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.

Report

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

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

Back to the form.

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

VBA

In-between Private Sub and End Sub, you're going to write

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天全站免登陆