0

我通过在 VBA 中编写查询来获取访问报告,并且它具有表的连接。问题是报告现在在报告中提取重复值。

ReCrt1 = "SELECT TeamDetails_v1.vName 
            FROM TeamDetails_v1 
            LEFT JOIN Attendance ON TeamDetails_v1.vName = Attendance.Name 
            WHERE ([Attendance!Team] In ('" & Mylist & "')) 
                AND ([Attendance!Dates]>Forms!AttendanceSummary!DTPicker0) 
                AND ([Attendance!Dates]<Forms!AttendanceSummary!DTPicker6) 
                AND ([TeamDetails_v1.vEmployment_Status]='Active')"
DoCmd.OpenReport "Monthly Report", acViewReport, , , , ReCrt1

SQL 语句中的换行符不在代码中。我把它放在那里是为了你方便。

我需要报告从“TeamDetails_v1”表中提取名称,该表只有唯一的名称记录并且在“vEmployment_Status”中处于“活动状态”。并且它们各自的记录数(在报告中使用计数公式)在“出勤”表中,其中日期应该在日期选择器控件的日期之间。“Mylist”是一个数组,其中包含基于列表框过滤的某些团队形式。

此处,报告不是从 TeamDetails_v1 中提取单个名称记录,而是在有 n 个日期时提取 n 个相同的数据。我在报告中只提供了一个文本框,其控制源为“TeamDetails_v1.vName”。我使用的 JOIN 是否有任何问题,还是文本框字段控制源?

4

1 回答 1

1

您是否尝试在 SELECT 之后放置关键字“Distinct”

 ReCrt1 = "SELECT DISTINCT TeamDetails_v1.vName FROM TeamDetails_v1 LEFT JOIN Attendance ON TeamDetails_v1.vName = Attendance.Name 
    WHERE ([Attendance!Team] In ('" & Mylist & "')) And ([Attendance!Dates]>Forms!AttendanceSummary!DTPicker0) And 
    ([Attendance!Dates]<Forms!AttendanceSummary!DTPicker6) And ([TeamDetails_v1.vEmployment_Status]='Active')"

        DoCmd.OpenReport "Monthly Report", acViewReport, , , , ReCrt1
于 2017-12-06T16:36:45.207 回答