求和字段如果不为空 [英] Summing Fields If Not Null

查看:192
本文介绍了求和字段如果不为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在表单上有5个字段。 Field1,Field2,Field3,Field4,SumField

SumField被禁用,因为它是基于其他四个字段计算的字段。


SumField = Field1 + Field2 + Field3 + Field4


如果值不为空,则只应对值进行求和。如果其中一个字段为null,则应跳过该字段。

此外,null字段应保持为null,代码不得将其转换为零。


示例:

Field1 = 5

Field2 = null

Field3 = null

Field4 = 10

SumField = 15

我知道我可以用每个字段的IF代码来完成它,但是这个领域有很多,它会使整个事情复杂化。

任何帮助表示赞赏。

解决方案

展开 | 选择 | 换行 | 行号


< BLOCKQUOTE> BTW。我刚刚尝试使用nz()函数,但它给了我运行时错误13(类型不匹配)。


代码是固定的,以便在更新Field1之后,Field2,Field3和Field 4 - 计算sub被调用,其中公式为。


是的,我试过使用nz(),但它给出了错误,请参阅我之前的回复。

我只在Field1(5)中输入了值。

当我去调试时,我看到整行用这个值突出显示为黄色:


SumField =""

Field1 = 5

Field2 =""

Field3 = "

Field4 =""


Hi,
I have 5 fields on a form. Field1, Field2, Field3, Field4, SumField
SumField is disabled as it is calculated field based on other four fields.

SumField = Field1 + Field2 + Field3 + Field4

It should only sum the values if they are not null. If one of the fields is null it should skip that field.
Also, null field should stay null, the code must not convert it to zero.

Example:
Field1 = 5
Field2 = null
Field3 = null
Field4 = 10
SumField = 15

I know I can do it with IF code for each field, but there is a lot of this fields and it would complicate whole thing.
Any help appreciated.

解决方案

Expand|Select|Wrap|Line Numbers


BTW. I''ve just tried to use nz() function, but it gives me run-time error 13 (Type mismatch).

The code is fixed so that after the update of Field1, Field2, Field3 and Field 4 - Calculating sub is called, where the formula is.


Yeah, I''ve tried to use nz(), but it gives error, see my previous reply.
I''ve only entered value in Field1 (5).
When I go to debug, I see whole line highlighted yellow with this values:

SumField = ""
Field1 = 5
Field2 = ""
Field3 = ""
Field4 = ""


这篇关于求和字段如果不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆