具有空值的 Dsum

Dsum with Null Value

我遇到了一些情况,希望您能指出正确的方向。

第一个 DSUM(文本 2):

=DSum("[quantity_ya7]","Stock","[part_number]= '" & [part_number] & "'")

第二个 DSUM(文本 2):(有时可以为 Null,因为没有取款或记录)

=DSum("[amt_ya7]","Withdrawal","[part_number]= '" & [part_number] & "' ")

设置好上面的2个DSUM后,我再进行减法

=文字1-文字2

如果有计算第二个DSUM的值,结果将按顺序显示。否则,它将是空的。 (没有显示值)

如何计算为 -0(减去 0)以便显示正确的值?

非常感谢。

You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. For example, you can use this function to convert a Null value to another value and prevent it from propagating through an expression.
https://support.office.com/en-gb/article/Nz-Function-8ef85549-cc9c-438b-860a-7fd9f4c69b6c

在您的情况下,当没有值时,您希望 DSUM 为 return 0 而不是 Null,因此您可以在计算中使用它。

=NZ(DSum("[amt_ya7]","Withdrawal","[part_number]= '" & [part_number] & "' "),0)