【问题标题】:MS Access: Create multiple reports from Same Query with different parametersMS Access:使用不同参数从同一查询创建多个报告
【发布时间】:2018-09-08 04:32:54
【问题描述】:

我有一个访问数据库,它基本上有一个表单,您可以在其中查找一些数据库条目。用户输入部件号,我检查它是否存在,如果存在,我会返回一份报告,其中所有数据都以易于阅读的方式组织。
问题是,假设我生成报告。然后返回表单查询其他部分,报告没有更新或没有生成新报告(即使我多次单击“查看报告”按钮)。
我想知道是否有一种方法可以生成一个新报告(使用相同的模板,来自相同的表单,不同的参数),并且能够有多个具有不同部分的相同模板的报告进行比较或仅用于分析。

【问题讨论】:

  • 您必须发布用于打开报告的代码。您使用的是 Open Report 方法吗?
  • 我自己没有编码。我使用“添加按钮”和命令按钮向导来“打开报告”。报告本身链接到表单

标签: ms-access


【解决方案1】:

由于表单可以多次使用,这也适用于报告。试试:

Dim rtp1 As Report_yourReportsName
Dim rtp2 As Report_yourReportsName
Set rpt1=New Report_yourReportsName
Set rpt2=New Report_yourReportsName
rpt1.visible=True
rpt2.visible=True

请记住将Report_ 放在报告名称前面,就像使用Form_ 一样。

用一个按钮打开最多 25 个报告的代码(名为 CommandOpenReports 的按钮):

'1) Declare a global variable (in the module header, outside of the subroutine) like this:

 'Assume we'll never need more than 25 instances of the
 'same report open at once
 Dim rpt(1 To 25) As Report


Private Sub CommandOpenReports_Click()
Dim I As Long
'2) set a member of the global array equal to the specific instance, filter according to whatever criteria you'd like, and make the instance visible.
For I = 1 To 25
    If rpt(I) Is Nothing Then
        Exit For
    End If
Next
'open rptPOs in separate windows
Set rpt(I) = New Report_Bericht1
rpt(I).Filter = stLinkCriteria
rpt(I).Visible = True

End Sub

Multiple Instances of a Report 盗取的代码

【讨论】:

  • 嗨,我应该在哪里添加此代码?我假设在表单上的“查看报告”按钮中?还是会出现在报告的 On Load 事件中?
  • 将其添加到您要打开报告的位置。例如,此代码一次打开 2 个实例。为简洁起见,为您要打开的每个报告(Button1、Button2、Button3)添加一个按钮,并使用一条暗线和一条带有 rptN 的设置线,其中 N 是按钮的编号。如果您想要无限的报告,您可以使用数组查看答案中的链接。
  • 计数器之类的东西有用吗?说 Dim rtp(counter) As Report_yourReportName Set rpt(counter)=New Report_yourReportName counter++ 注意这将在 Swift 中,我不知道如何在 VBA 中附加一个计数器
  • 我正在尝试您提到的代码,但是我在 Set rpt(I) = New Report_ViewData.它说未定义用户定义的类型。我在 Microsoft Access 类对象的项目数据库树中查找它只列出了 Form_ 对象。它没有列出任何 Report_ 对象(我在数据库中有 3 个报告模板)我不知道这是否与此有关
  • 报告ViewData不包含vba-code吗?如果不添加一个空的虚拟事件(例如Report_Open()),那么它应该在项目中可见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-12
  • 1970-01-01
相关资源
最近更新 更多