从日期范围转换为月份范围

时间:2017-01-31 15:02:56

标签: vba ms-access access-vba ms-access-2010

我想将以下内容从设定日期范围转换为整月范围:

Set rs = CurrentDb.OpenRecordset("SELECT Count(Advisors) AS TotalNumber FROM tbl_ComplaintsCoded WHERE Advisors = '" & Forms!frm_Central_Reporting_ops!Label44.Caption & "' AND [Mail Date] between #01/04/2016# AND #30/04/2016#")

我试过了:

Set rs = CurrentDb.OpenRecordset("SELECT Count(Advisors) AS TotalNumber FROM tbl_ComplaintsCoded WHERE Advisors = '" & Forms!frm_Central_Reporting_ops!Label44.Caption & "' AND month[Mail Date] ='April'")

也尝试过:

Set rs = CurrentDb.OpenRecordset("SELECT Count(Advisors) AS TotalNumber FROM tbl_ComplaintsCoded WHERE Advisors = '" & Forms!frm_Central_Reporting_ops!Label44.Caption & "' AND month[Mail Date] ='4'")

提前感谢您的帮助

1 个答案:

答案 0 :(得分:1)

如前面的评论所述,您可能也想参考一年,否则所有“四月”项目都将包括在内,无论年份如何。

Set rs = CurrentDb.OpenRecordset("SELECT Count(Advisors) AS TotalNumber FROM tbl_ComplaintsCoded WHERE Advisors = '" & Forms!frm_Central_Reporting_ops!Label44.Caption & "' AND month([Mail Date]) =4")