11. november 2005 - 12:36Der er
10 kommentarer og 1 løsning
Using Nz function
Why can I not set field property to Standard and get 2 decimals on values from a Nz function? Also, if I add a value from a Nz function and another value from a Nz function, the second will be added after the first. If the first is 222 and the second is 333 the result will be 222333 and not 555. Why is that?
One example is: Me.Taxkredit = Nz((DSum("DEBITERAS", "Resapost", "(Resapost.SlutDat Between Forms.Rapport.StartDag And Forms.Rapport.SlutDag) And (Resapost.Taxinr = Forms.Rapport.Taxinr) And (Resapost.ARBPASSNR = Forms.Rapport.Rapport) And (Resapost.FORAR_ID = Forms.Rapport.Forarnr) And (Resapost.KREDITTYP > 3)")) - (DSum("DRICKS", "Resapost", "(Resapost.SlutDat Between Forms.Rapport.StartDag And Forms.Rapport.SlutDag) And (Resapost.Taxinr = Forms.Rapport.Taxinr) And (Resapost.ARBPASSNR = Forms.Rapport.Rapport) And (Resapost.FORAR_ID = Forms.Rapport.Forarnr) And (Resapost.KREDITTYP > 3)")), 0)
Not quite sure I understand the problem, you should use NZ on each field in the calculated value. If a field is NULL (which is not the same as 0 (zero)) then nz can be sued to return a value for example 0. Otheriwse your calculation is going to fail if one field is NULL and others arent.
That's quite a long Dsum. Usually using nested aggregate functions (dsum,dlookup etc) can slow the form down. If the purpose is to display a number in a text field I'd consider doing it via VBA that runs on the forms current_event. It'll be much quicker.
Does something like this work?:
Me.Taxkredit = Format(Cdbl(Nz((DSum("DEBITERAS", "Resapost", "(Resapost.SlutDat Between Forms.Rapport.StartDag And Forms.Rapport.SlutDag) And (Resapost.Taxinr = Forms.Rapport.Taxinr) And (Resapost.ARBPASSNR = Forms.Rapport.Rapport) And (Resapost.FORAR_ID = Forms.Rapport.Forarnr) And (Resapost.KREDITTYP > 3)")) - (DSum("DRICKS", "Resapost", "(Resapost.SlutDat Between Forms.Rapport.StartDag And Forms.Rapport.SlutDag) And (Resapost.Taxinr = Forms.Rapport.Taxinr) And (Resapost.ARBPASSNR = Forms.Rapport.Rapport) And (Resapost.FORAR_ID = Forms.Rapport.Forarnr) And (Resapost.KREDITTYP > 3)")), 0)),"0.00")
The suggestion from You, jesperfjoelner, seems to work if it just is a matter of displying a nbr in a text field, but the value is stored for later calculations. What happens then?
Forget about the last question. It's of course still a Nz function. What happens is that the value from DRICKS is deducted from the value from DEBITERAS. Both values should meet the same criteria. Is it possible to simplify the code?
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.