Calculated unbound field on form

ralphyehle

Registered User.
Local time
Today, 21:32
Joined
Aug 28, 2002
Messages
22
My calculated unbound field 'txtTotalCost' does not add the fields that people use to enter data, if the $0.00 in any one of the fields is deleted. The calculated field sums five bound fields, if one of them is null, then the calculated field does not add the other 4. The default value is set to $0, but if I delete the zero and leave a field null then the calculation fails. I could use a validation rule to require "Is Not Null" but what I'd like is a calculation that will continue to add up the other four fields even if one field is null. Any thoughts?
 
Encapsulate your fields in the Nz function:

=Nz([field1],0) + Nz([field2],0)

etc.
 
problem fixed

thanks for the simple fix.
 
Hi Boblarson,

Can I use =Nz([field1],0) + Nz([field2],0) with devide in stead of plus?

Cheers,
 
Hi Boblarson,

Can I use =Nz([field1],0) + Nz([field2],0) with devide in stead of plus?

Cheers,

Yes you can but remember you should never divide by Zero. That is always a no-no
 
but...if I use func "Nz"...the data in the table will be INcorrect. If I use "Is Not Null" in validation rule, Iwill be sure that I can use data in further without worry. Is this logic(right)?
 
If you have nulls or zeros then you would want to test for null or zeroes first and then return a 0 if null or 0 in the field2:

=IIf(Nz([Field2],0)=0,0,Nz([field],0)/[Field2])
 
rosito, You've hijacked this thread and start by saying that using Nz() will give you incorrect data in your table, and you haven't told us a single word about what you're trying to do! If you're speaking of storing a calculated value in a table, then this in itself is frowned on in most situations.
 
missinglinq, i m sorry.. I want not this. sorrrrry
 
Thank you so much Boblason,

That codes works calculation on a main form. I also have a other question please.

On a subsform, I als like to have the calculation, by having the Advance field divided by the exchange rates (these two field are on the mainform) then appears result in subform.

currently, I use

=([txtTotalStanding(KIP)]/(Forms!frmPaymentSADU!txtRates)) however, by using this gives me #Num when the OtherCurrency field=0.

Is there anyhow for sending the results of Sumtotal in either form, subform and report to the table, sorry I just would like confirm this again. I don't quite understand what Rosito mentioned above.

Thank you

Cheers,
 
Can I use =Nz([field1],0) + Nz([field2],0) with devide in stead of plus?

Rabbie warned you against dividing by Zero, but really didn't answer your question. The answer is Yes, you can use Nz() for dividing, with a little change. The default replacement argument for Nz() is Zero, as in

Nz([field1],0)

but you can change thios argument to something else.

If, for instance, you want to use field1 as the divisor in a calculation, you need, as Rabbie said, not to have it equal to Zero, so you change the argument to 1.

Nz([field1],1)

If field1 is Null, it'll now be replaced by 1.

If you have a number and don't want it divided by anything, you actually want it to remain the same, and any number divided by 1 remains the same!.

If field1 is Null, you want 10 divided by field1 to equal 10. So if field1 is Null,

10 / Nz([field1],1)

then becomes

10 / 1

which equals 10, your desired results!

Note that Nz() can also be used for text values. Say, for example, you have a field in a report that holds clients (txtClient) and a field that holds agents (txtAgent). If a client doesn't have an agent assigned to them, the txtAgent field will be Null, and nothing will print under the agent field for that client. But by using

Nz([txtAgent], "Unassigned")

if there's nothing in the txtAgent field, "Unassigned" will now be printed instead of a blank.
 
Rabbie warned you against dividing by Zero, but really didn't answer your question.
Linq, The first words of my reply were "Yes you can" which I thought answered the question. I then cautioned about the dangers of division by zero because I know from experience the problems that can cause.
 
I know, Rabbie, just meant that you didn't explain to the OP how they could use it in division.
 
I know, Rabbie, just meant that you didn't explain to the OP how they could use it in division.
I guess that's because I like people to think for themselves after being shown the right way to proceed:o
 
Now I full understood.

Thank you so much to you guy been doing a great job helping peaple all a round the world sorting out these db issues, guiding them on what they have been doing right to the direction.
I really appreciate that.
Cheers,
 

Users who are viewing this thread

Back
Top Bottom