我有关于值和空值之和的问题。我想要实现的是将值设置为Sum,而不管是否具有空字段。这是我的代码形式:
Public Sub projectname_Change()
Me.total1_n = DSum("SumBudgeted_amount2", "second_q")
Me.total2_n = DSum("SumBudgeted_amount2", "second_q2")
Me.total3_n = DSum("SumBudgeted_amount2", "second_q3")
Me.total4_n = DSum("SumBudgeted_amount2", "second_q4")
End Sub
有second_q区域的空值。即使一个字段有一个值,因为o null值,程序会给出错误。我试着添加
Me.total1_n = DSum("SumBudgeted_amount2", "second_q", [Nz(second_q,[0])])
代码在所有second_qs的末尾,也尝试了IIf(IsNull ...代码。但是,它们没有用。请帮我解决这个问题。
答案 0 :(得分:0)
试试这个
Me.total1_n = DSum("Nz([SumBudgeted_amount2],0)", "second_q")
或
Me.total1_n = DSum("Nz(SumBudgeted_amount2,0)", "second_q")
(数据库函数对方括号的存在或不存在很挑剔。)
我真的不相信NZ()并且总是避免它:
Me.total1_n = DSum("IIf(SumBudgeted_amount2 Is Null,0,SumBudgeted_amount2)", "second_q")
尝试使用和不使用方括号。