Avatar billede nyholm Novice
11. november 2005 - 12:36 Der 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?
Avatar billede jesperfjoelner Nybegynder
11. november 2005 - 13:04 #1
Formentlig fordi værdien bliver opfattet som tekst.

Måske virker:

Dim a as string
Dim b as string

a="222"  'er tekst
b="333"  'er tekst

debug.print a+b    'giver 222333
debug.print cdbl(a) + cdbl(b)  'giver 555
Du kan også bruge andre konverteringsfunktioner: cLng, cSng, cInt

Problemer er nok at nz() funktionen returnerer tekst i stedet for tal.

Har dog ikke testet ovenstående.
Avatar billede nyholm Novice
11. november 2005 - 13:19 #2
Is there other ways to get the result 0(zero)if no matches are found in a query and that does'nt change the property to text?
Avatar billede jesperfjoelner Nybegynder
11. november 2005 - 15:19 #3
I think so. Is it a regular query?
Or are you using SQL via VBA?
Can you show a piece of the code?
Avatar billede nyholm Novice
11. november 2005 - 15:30 #4
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)
Avatar billede terry Ekspert
11. november 2005 - 20:14 #5
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.

Hope you understand that.
Avatar billede jesperfjoelner Nybegynder
11. november 2005 - 21:22 #6
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")
Avatar billede nyholm Novice
11. november 2005 - 21:43 #7
Terry, I want 0 as the result if no records are found that meets the criteria.
jesperfjoelner, i will try and see if it works.
Avatar billede nyholm Novice
11. november 2005 - 22:04 #8
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?
Avatar billede nyholm Novice
11. november 2005 - 22:16 #9
I seems to work even in later calculations.
Does this method work faster then the Nz function?
Avatar billede nyholm Novice
11. november 2005 - 22:26 #10
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?
Avatar billede jesperfjoelner Nybegynder
29. marts 2006 - 18:15 #11
Mange tak :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester