简体   繁体   中英

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.

Now i want to have another text box (#3) that divides one by the other for a very simple percentage. 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! 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.

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?

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:

=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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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