title: Division by 0 Error when no division is happening
body: <p>I am running a simple insert query in vba </p>
  
  <pre><code>DoCmd.RunSQL "INSERT INTO tblBldgComparePer ( Bldg, Utility, LYRAvgUnits, LYRAVGUNITDif, LYRUnits, LYRUNITDIF, PrevMonUnits, PMUNITDIF, CurrentUnits, AvgOfTotCost, LYRAVGCOSTDif, LYRTotCost, LYRCOSTDIF, PrevMonTotCost, PMCOSTDIF, CurrentTotCost ) SELECT qryBldgComparePer.Bldg, qryBldgComparePer.Utility, qryBldgComparePer.LYRAvgUnits, qryBldgComparePer.LYRAVGUNITDif, qryBldgComparePer.LYRUnits, qryBldgComparePer.LYRUNITDIF, qryBldgComparePer.PrevMonUnits, qryBldgComparePer.PrevMonUNITDif, qryBldgComparePer.CurUnits, qryBldgComparePer.LYRAVGTotCost, qryBldgComparePer.LYRAVGTotCostDif, qryBldgComparePer.LYRTotCost, qryBldgComparePer.LYRTotCostDIF, qryBldgComparePer.PrevMonTotCost, qryBldgComparePer.PrevMonTotCostDif, qryBldgComparePer.CurTotCost FROM qryBldgComparePer;", False
  </code></pre>
  
  <p>However I am getting a divide by 0 error when I run this query. The query it is based on, <code>qryBldgComparePer</code> shows up just fine, and has no divide by 0 errors in it. There are possibilites where it could, but the fields where it could I put in an IIF statement if the denominator is 0 to just make the field = 0 instead. Is this somehow being bypassed when inserted, so that it is trying to divide by 0? I have looked online and have not found another case like this. Any help you guys can offer would be very appreciated. Thank you!</p>
  
  <p>This is all the code leading up to the error:</p>
  
  <pre><code>strSQL = "SELECT bc.Bldg, bc.Utility, bc.LYRAVGUnits, IIF( bc.LYRAvgUnits = 0, NULL, Abs(([bc].[LYRAvgUnits]-[bc].[CurUnits])/[bc].[LYRAvgUnits])) AS [LYRAVGUNITDif], bc.LYRUnits, IIF( bc.LYRUnits = 0, NULL, Abs(([bc].[LYRUnits]-[bc].[CurUnits])/[bc].[LYRUnits])) AS [LYRUNITDif], bc.PrevMonUnits, IIF( bc.PrevMonUnits = 0, NULL, Abs(([bc].[PrevMonUnits]-[bc].[CurUnits])/[bc].[PrevMonUnits])) AS [PrevMonUNITDif], bc.CurUnits, bc.LYRAVGTotCost, IIF(bc.LYRAvgTotCost = 0, NULL, Abs(([bc].[LYRAvgTotCost]-[bc].[CurTotCost])/[bc].[LYRAvgTotCost])) AS [LYRAVGTotCostDif], bc.LYRTotCost, IIF(bc.LYRTotCost = 0, NULL, Abs(([bc].[LYRTotCost]-[bc].[CurTotCost])/[bc].[LYRTotCost])) AS [LYRTotCostDif], bc.PrevMonTotCost, IIF( bc.PrevMonTotCost = 0, NULL, Abs(([bc].[PrevMonTotCost]-[bc].[CurTotCost])/[bc].[PrevMonTotCost])) AS [PrevMonTotCostDif], bc.CurTotCost FROM qryBldgCompare AS bc " &amp; _
  "WHERE (bc.CurUnits &lt;&gt; 0) AND ((((Abs(([bc].[LYRAvgUnits]-[bc].[CurUnits])/[bc].[LYRAvgUnits]))&gt;" &amp; PerDif &amp; ")) OR (((Abs(([bc].[LYRUnits]-[bc].[CurUnits])/[bc].[LYRUnits]))&gt;" &amp; PerDif &amp; ")) OR (((Abs(([bc].[PrevMonUnits]-[bc].[CurUnits])/[bc].[PrevMonUnits]))&gt;" &amp; PerDif &amp; ")) OR (((Abs(([bc].[LYRAvgTotCost]-[bc].[CurTotCost])/[bc].[LYRAvgTotCost]))&gt;" &amp; PerDif &amp; ")) OR (((Abs(([bc].[LYRTotCost]-[bc].[CurTotCost])/[bc].[LYRTotCost]))&gt;" &amp; PerDif &amp; ")) OR (((Abs(([bc].[PrevMonTotCost]-[bc].[CurTotCost])/[bc].[PrevMonTotCost]))&gt;" &amp; PerDif &amp; ")));"
  CurrentDb.QueryDefs("qryBldgComparePer").SQL = strSQL
  DoCmd.RunSQL "DELETE FROM tblBldgComparePer;"
  DoCmd.RunSQL "INSERT INTO tblBldgComparePer ( Bldg, Utility, LYRAvgUnits, LYRAVGUNITDif, LYRUnits, LYRUNITDIF, PrevMonUnits, PMUNITDIF, CurrentUnits, AvgOfTotCost, LYRAVGCOSTDif, LYRTotCost, LYRCOSTDIF, PrevMonTotCost, PMCOSTDIF, CurrentTotCost ) SELECT qryBldgComparePer.Bldg, qryBldgComparePer.Utility, qryBldgComparePer.LYRAvgUnits, qryBldgComparePer.LYRAVGUNITDif, qryBldgComparePer.LYRUnits, qryBldgComparePer.LYRUNITDIF, qryBldgComparePer.PrevMonUnits, qryBldgComparePer.PrevMonUNITDif, qryBldgComparePer.CurUnits, qryBldgComparePer.LYRAVGTotCost, qryBldgComparePer.LYRAVGTotCostDif, qryBldgComparePer.LYRTotCost, qryBldgComparePer.LYRTotCostDIF, qryBldgComparePer.PrevMonTotCost, qryBldgComparePer.PrevMonTotCostDif, qryBldgComparePer.CurTotCost FROM qryBldgComparePer;", False
  </code></pre>