vba 控制源 If 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10902712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:23:10  来源:igfitidea点击:

Control Source If statement

ms-accessvbaaccess-vbams-access-2003

提问by Ish

I want access to automatically calculate the output if the entered value is > 0. So I put the following code in the "Control Source" field of a textbox property and it is giving me an error. The Number should be obtained from Text052 and it should output it in Text054.

如果输入的值 > 0,我希望访问自动计算输出。所以我将以下代码放在文本框属性的“控制源”字段中,它给了我一个错误。Number 应该从 Text052 获得,它应该在 Text054 中输出它。

Here is the code:

这是代码:

If Text052.value > 0 then
Text054.value = Val([Text052].[Value])/2
end if

Error: "The expression you enetered contains invalid syntax". "You have enetered the operand without the operator"

错误:“您输入的表达式包含无效语法”。“您在没有运算符的情况下输入了操作数”

I am not sure how to write the syntax in the control source field of the text box propety. Please advice.

我不确定如何在文本框属性的控件源字段中编写语法。请指教。

回答by Fionnuala

In the control source of Text054, try:

在Text054的控件源中,尝试:

=IIf([Text052] > 0,[Text052]/2, "N/A")

"N/A" can be whatever you need, including null.

“N/A”可以是您需要的任何内容,包括空值。