Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11

    Error Divided by zero when return with query


    [Field1]/[Field2]+[Field3]*1000. If Field2 or Field3 are empty i got Error Divided by Zero in Query.

    In Field4 i want the answer. How will i use the Iif statement?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe:
    Code:
    IIF(NZ([Field2],0) = 0, 0, NZ([Field1])/[Field2] + NZ([Field3],0) *1000)

    Edit: I changed my answer to match Ajax. His answer was better than mine.

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,439
    iif(isnull(field2),0,nz([Field1])/[Field2]+nz([Field3])*1000)

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Not sure this would work but you might try:
    Code:
    Nz([Field1],0)/Nz([Field2],0)+Nz([Field3],0)*1000.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    If field is Null the return should be Null and no error. So why is there division by 0?

    Bob, to prevent division by zero the alternative value from Nz() in denominator would have to be 1, not 0.

    Algebraic order of operations apply - the division and multiplication will take place before the addition unless you use parens.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11
    Nope, it´s not working. Now error, You have left out operand or operator

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    I don't see anything wrong with examples. Post your actual attempted expression.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11
    IIF(NZ([SummaV],0) = 0, 0, NZ([SummaFel])/[SummaV] + NZ([Summa1],0) *1000)

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    That looks good.

    Post the entire SQL statement or provide db for analysis. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe:
    IIF(NZ([SummaV],0) = 0, 0, NZ([SummaFel],0))/[SummaV] + NZ([Summa1],0) *1000)

  11. #11
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11
    My Access is in Swedish . If i try that in the picture i get the true value, not the false.
    i really suck in Access....

    Click image for larger version. 

Name:	Namnlös.png 
Views:	12 
Size:	4.2 KB 
ID:	23486

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    I am guessing OOM means IIf.

    Not seeing anything that looks like IsNull() or Nz() function.

    The examples given are quite explicit. Just need to follow one.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11
    Tried Everything but nothing works

  14. #14
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11
    It says i missed and operand or operator

    Click image for larger version. 

Name:	Namnlös1.png 
Views:	12 
Size:	9.4 KB 
ID:	23487

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Looks like missing ) for the first Nz() and one after 1000 although looks some kind of character in those places.

    OOM(Nz([SummaV],0) = 0, 0, Nz([SummaFel],0)/[SummaV] + Nz([Summa1],0) * 1000)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 06-11-2014, 08:06 AM
  2. Running Sum divided by Month Total
    By kwooten in forum Reports
    Replies: 7
    Last Post: 05-16-2013, 10:20 AM
  3. Total divided by weekdays in a month
    By normie in forum Access
    Replies: 1
    Last Post: 03-22-2012, 07:09 PM
  4. 0 divided by 0 = impossible..
    By LanieB in forum Queries
    Replies: 13
    Last Post: 01-03-2012, 05:24 PM
  5. Replies: 1
    Last Post: 02-01-2010, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums