计数记录并在不存在的情况下返回零

时间:2016-02-07 12:42:13

标签: vba ms-access access-vba

我需要从表中总计一笔金额。如果没有记录,我的函数必须返回零,但事实并非如此。我得到'#Error'。这是我的功能:

Public Function Fees() As Double

Fees = Nz(DSum("MyFee", "tblDisclosure", "Volunteer = True And Not IsNull(ReceiptsLookup) and RequestDate> DateSerial(Year (Date),Month (Date),1)-1"), 0)

End Function

1 个答案:

答案 0 :(得分:0)

尝试使用正确的标准字符串:

Public Function Fees() As Double

    Fees = Nz(DSum("MyFee", "tblDisclosure", "Volunteer = True And Not IsNull(ReceiptsLookup) And RequestDate > DateSerial(Year(Date()), Month(Date()), 0)"), 0)

End Function