我需要计算过去十二个月人们轮班的次数。我想用DateSerial
. 如果我输入实际日期而不是DateSerial
. 我通过更改DateSerial
为返回十二个月前以外的日期来测试我的代码,但我的代码总是给出所有数据总和的数字 - 追溯到十二个月以上。所以它忽略了 MyDt。我哪里错了?
Public Function Shifts() As Integer
Dim MyDt As Date
MyDt = DateSerial(Year(Date), Month(Date) - 12, 1) - 1
Shifts = DSum("Shifts", "tblWorkNew", "GP = " & GPLookup & "And Month > #31/10/2012#") 'This works for any date.
Shifts = DSum("Shifts", "tblWorkNew", "GP = " & GPLookup & "And Month > " & MyDt) 'This only gives all data, i.e. ignores MyDt
End Function