Results 1 to 7 of 7
  1. #1
    lugnutmonkey is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    42

    how to avoid #Div/0! error

    I have a query that returns the Delta % for pair of data points. I use this information in a report. Due to the nature of the report some data points have a zero value. This is not a problem when the zero is the second value as it just returns an unusual % change. The real problem for my managers is the #Div/0! error message that comes up when it attempts to divede by zero.

    Code:
     Delta: ([Test1]-[Test2])/[Test1]))
    What would I have to add to the above expression to avoid the division by 0 error?

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Have you considered using an IIF (,,) Statement?

  3. #3
    lugnutmonkey is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    42
    I have, I don't know how I would use the error as the arugement so that if it was a #Div/0! error it would display "0" or some pre-defined text.

  4. #4
    cphelps is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    6
    Unless there is more to your requirements you could make an assumption that negates the need to check for an error by using an Iif statement like =IIF([Test1]=0,0,([Test1]-[Test2])/[Test1]).

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    cp, that expression should still error. Reason is all parts of IIf must be able to evaluate, even if it is not the part that returns result. So there is still an expression that will try to divide by 0 and the #Div/0! error will trigger.

    Delta: ([Test1]-[Test2])/IIf([Test1]=0,1,[Test1])

    or

    Delta: IIf([Test1]=0,"No Value", ([Test1]-[Test2])/IIf([Test1]=0,1,[Test1]))
    Last edited by June7; 04-15-2013 at 08:09 PM.
    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
    lugnutmonkey is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    42
    Thank you June7, They both work. I prefer the second solution becasue it provides the ability to deliver a message in place of arbitrary result. the only problem I am having with it is that the Percent formatting I hade on the field is lost when one of the results of the IIF function is a calculated result.

    Is there anyway that I could dictate the format of the result through code as opposed to using the properties menu?

  7. #7
    lugnutmonkey is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    42
    Answered my own question, FormatPercent(, sorry to bother you.

    Thanks for all the help!!!

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

Similar Threads

  1. avoid sql server authentication
    By JJCHCK in forum Programming
    Replies: 0
    Last Post: 02-23-2012, 10:36 AM
  2. How do I avoid multiple entries
    By schwabe in forum Queries
    Replies: 2
    Last Post: 02-01-2012, 04:16 PM
  3. How To Avoid Using Three Field Composite Key
    By Lady_Jane in forum Database Design
    Replies: 14
    Last Post: 08-17-2011, 03:40 PM
  4. Hi, How do we avoid repeated records?
    By radicrains in forum Queries
    Replies: 11
    Last Post: 11-04-2010, 03:00 AM
  5. Maximun View; How to Avoid
    By cassidym in forum Database Design
    Replies: 1
    Last Post: 08-12-2010, 06:59 PM

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