Results 1 to 4 of 4
  1. #1
    chriswrcg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Philippines
    Posts
    142

    replace #Num! with 0

    every so often I will be faced with the following calculation in access. 0/452. (zero divided by some other number)
    inevitably the end result in access is the #Num! result instead of just displaying 0.



    What can I do to prevent this?

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You wouldn't get the NUM error by dividing 0 by some number. 0 divided by any number returns 0, and Access has no problems with that.
    It has a problem going the other way, if you try to divide some number by 0 (for example, 452/0), as that is an illegal mathematical operation (not uniquely an Access thing).

    The way around that is to first check to see if the field you are dividing by is zero first.
    For example, if you were dividing Field1 by Field2, the modified calculation should look like:
    Code:
    IIF([Field2]=0,0,[Field1]/[Field2])

  3. #3
    chriswrcg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Philippines
    Posts
    142
    Thanks so much. I didn't think the placement of the 0 made that much of an impact.

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome.

    0 can never be in the divisor. It is a mathematical rule, as division by 0 makes no mathematical sense.

    Here are some good write-ups/explanations on it.
    http://mathforum.org/dr.math/faq/faq.divideby0.html
    The "Elementary Arithmetic" section here: https://en.wikipedia.org/wiki/Division_by_zero

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replace statment
    By jagrok in forum Access
    Replies: 16
    Last Post: 02-11-2015, 04:20 PM
  2. Replace _ when #_#
    By wellsw in forum Queries
    Replies: 5
    Last Post: 11-22-2013, 06:32 PM
  3. replace . with /
    By msasan1367 in forum Access
    Replies: 1
    Last Post: 08-05-2013, 06:21 AM
  4. Replies: 3
    Last Post: 06-07-2012, 07:05 AM
  5. Replace "
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 05-10-2011, 07:09 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