過去 12 か月間に人々が働いたシフトの数を数える必要があります。使いたいですDateSerial
。ではなく実際の日付を入力すると、コードが機能しますDateSerial
。DateSerial
12 か月前以外の日付を返すように変更してコードをテストしましたが、コードは常にすべてのデータの合計の数値を示します - 12 か月以上さかのぼります。したがって、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