简体   繁体   English

MS Access 2003-表单上的文本框计算

[英]MS Access 2003 - text box calculation on a form

Lets say I have two text boxes on a form. 可以说我在表单上有两个文本框。 the first returns a count value from a SQL statement, or a domain aggregate expression, etc. the second does the same with additional parameters. 第一个返回来自SQL语句或域聚集表达式等的计数值。第二个返回相同的参数。

Now i want to have another text box (#3) that divides one by the other for a very simple percentage. 现在,我想拥有另一个文本框(#3),以非常简单的百分比将另一个文本框分开。 like this for a controlsource: 像这样作为控制源:

=[textbox2]/[textbox1]

this works great unless the original counted value returned is a zero. 除非返回的原始计数值为零,否则这很有用。 If the first returned value is a zero, then the second is going to be a zero too, and ideally 0 / 0 should come out to zero, but I get a #Num! 如果第一个返回的值为零,那么第二个也将为零,理想情况下,0/0应该为零,但是我得到了#Num! error string in the text box. 文本框中的错误字符串。

I realize this is yet another weird request but this is for a dashboard form that has about 50 of these, and they work great, unless I hit a zero. 我意识到这是另一个怪异的要求,但这是针对仪表板表单的,其中包含约50个,并且除非我打零,否则它们的效果很好。

So is there any way I can set text box properties that i may be unaware of, for this to work without having to write numerous If statements in the code? 那么,有什么方法可以设置我可能不知道的文本框属性,而无需在代码中编写大量If语句就可以使它起作用?

Thanks! 谢谢!

我看不到如何避免被零除的if语句

=IIf(TextBox1<>0, TextBox2/TextBox1,"N/A")

Mathematically, the division by 0 is undetermined, but for your purposes, you can calculate it with: 在数学上,除以0是不确定的,但是出于您的目的,您可以使用以下方法进行计算:

=IIf([textbox1]<>0;[textbox2]/[textbox1];IIf([textbox2]=0;0;"N/A"))

This is, when textbox1 equals 0, you check whether or not textbox2 equals 0. If this is the case, then return 0, which is what you want. 即,当textbox1等于0时,您检查textbox2是否等于0。如果是这种情况,则返回0,这就是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM