1

我对值和空值的总和有疑问。无论有空字段,我想要实现的是总和的值。这是我的代码形式:

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 为空值,程序也会出错。我试图添加

Me.total1_n = DSum("SumBudgeted_amount2", "second_q", [Nz(second_q,[0])])

所有 second_qs 末尾的代码,还尝试了 IIf(IsNull... 代码。但是,它们不起作用。请帮我解决这个问题。

4

1 回答 1

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")

尝试使用和不使用方括号。

于 2013-07-17T14:30:13.540 回答