【问题标题】:Linking master report and subreport when rewriting the subreport datasource重写子报表数据源时链接主报表和子报表
【发布时间】:2016-05-06 13:27:59
【问题描述】:

我有一组“主”表(TableA、TableB、TableC),每个表都可以通过联结表(jctTableAX)选择性地链接(多对多)到一组“链接”表(TableX、TableY、TableZ) 、jctTableAY、jctTableAZ 等)

表格中的每个项目都有一个唯一的(长)标识符(例如 Aid、Xid),用于构建链接和一个唯一的(字符串)选择器(例如 ASelector、XSelector),显示给用户。

每个主表或链接表都有一个关联的查询(例如 qryA、qryX),它会拉出所有表数据并通过 Selector 对其进行排序。

我想生成一组报告,显示“主”表 (A/B/C) 中每个项目的完整详细信息;每个报告都有一组三个子报告,显示链接选择器的列表。

(实际上有十几个主表和十几个链接表,根据上下文,有些表可以是主表或链接表,所以我需要一个通用的可扩展解决方案——最多的子报表将是然而,在任何报告中都是 4,因为并非所有表格链接的组合都受支持。)

我当前的设计为每个主表都有一个报告,每个链接表都有一个子报告。这些子报表包含在每个主报表中,因此子报表的数据源在子报表打开事件中被重写(示例是 X 类型链接项目的子报表)

     Dim strMasterType As String
     Dim strJunctionTable As String
     Static intCallCount As Long

     If intCallCount = 0 Then 'Only execute this once

         strMasterType = FormItemType(CurrentMasterForm) 'returns A B or C
         strJunctionTable = GetJunctionTable(strMasterType, "X") 'returns the relevant junction table name

         Me.RecordSource = "SELECT " & strJunctionTable & ".*,  qryX.*, " & strJunctionTable & "." & strMasterType & "id AS MasterID FROM " & strJunctionTable & " LEFT JOIN qryX ON " & strJunctionTable & ".Xid = qryX.Xid;"


     End If
     intCallCount = intCallCount + 1

Link Master Field 是 Aid。链接子字段是 MasterID(这些是在报表设计时设置的,但我相信这应该让我为不同的主报表重写子报表源,只要子报表源中始终包含 MasterID 字段。)

  1. 这种设计是否合理或有更好的方法来解决这个问题?
  2. 链接主字段/链接子字段设置或 RecordSource SQL 中存在问题,因为即使主项之间的链接数据不同,我在子报表中获得相同的数据,但我正在编写代码-blind 试图解决它。

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    我认为您所描述的内容听起来很合理,但我不确定更详细的信息。我建议在设计视图中删除 Link Master & Child 的设置;从父报表的子报表控件中删除子报表本身也是一个好主意。如果您这样做了,当报表打开时,主报表的 open 事件将触发(因为尚不存在子报表):

    private sub report_open(cancel as integer)
        me.recordsource = ...
        me.childreport1.sourceobject = ... 'name of child report; 
            'this line will cause the open event of the sub report to fire; 
            'use that event to set the sub-report's record source by
            'if me.recordsource = "" then 
            '    me.recordsource = ... 
        me.childreport1.linkmasterfield = ... 'or whatever the property is called
        me.childreport1.linkchildfield = ...
    end sub
    

    这种方法在一个表单中很有效,它根据用户在另一个控件中的选择在同一个子表单对象中显示不同的子表单,所以我希望它也适用于您的应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多