Results 1 to 4 of 4
  1. #1
    BP2E is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    4

    Angry Query Expression Division Error - #Num! and #Div/0!


    My expression is subtracting the monthly charges vs budgeted charges, then dividing the total by the budgeted charges and shown as a percentage. If monthly charges and budgeted charges both have a zero total a "#Num!" returns. If only one of the data fields has zero total a "#Div/0!" returns. I would like to run an if statement which replaces all "#Num!" and "#Div/0!" values with "0.00%". I've tried the IIF statement but returns saying invalid syntax.
    As you can tell, I solidly fall into the Beginner category of access.
    Thanks!

    Expr4: [Expr2]/[2016 Median wRVU per Physician Spread Query]![Aug-15]

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    instead of doing the division ,paste this custom function into a module so all queries can use it.

    press ALT-F11
    (on the menu, INSERT, MODULE)
    paste the code below
    save (module1 is fine)


    in a query instead of the :[Expr2]/[2016 Median wRVU per Physician Spread Query]![Aug-15]
    in a query field, use: Pct: CalcPct([expr2], [2016 Median wRVU per Physician Spread Query]![Aug-15])

    Code:
    
    
    Code:
    Public Function CalcPct(ByVal pvTop, ByVal pvBtm)
    If pvTop = 0 Or pvBtm = 0 Then
       CalcPct = 0
    Else
       CalcPct = pvTop / pvBtm
    End If

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Check to see if the denominator is zero, i.e:
    Code:
    Expr4: IIF([2016 Median wRVU per Physician Spread Query]![Aug-15]=0,0,[Expr2]/[2016 Median wRVU per Physician Spread Query]![Aug-15])
    If Expr2 is zero, it should just return 0, not an error (it is OK to have 0 in the numerator).

    IF Expr2 is another calculation that is returning an error, it is best to address that error directly in that calculation. So you will need to check to the calculation of Expr2. Maybe that is also dividing by zero, in which case you would handle that calculation the same was as we handled this one above.

  4. #4
    BP2E is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    4
    The formula worked perfectly. Thanks to both of you for your help!

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

Similar Threads

  1. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  2. #Num! error division by 0
    By smc678 in forum Access
    Replies: 5
    Last Post: 10-14-2013, 11:41 AM
  3. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Division by zero error on a query
    By thorwood in forum Access
    Replies: 3
    Last Post: 05-19-2011, 07:20 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