title: SQL SUM statement in VBA function
body: <p>My database has three tables, Holder, Product (which is an account) and Transaction. I have set up a form from the Holder table that has a subform from the Product table and the Product subform has the Transaction table as a subform. On the Holder portion of the form, I have put an Outstanding unbound text field that should display the total amount and tax fields of transactions from the transaction table that have not been paid (indicated by a checkbox on the Transaction table). I have set the control source of the unbound text box to =calcOutstanding() and written the following function for the form. </p>
  
  <p>Public Function calcOutstanding()</p>
  
  <pre><code>Dim db As Database
  Dim strSQL As String
  
  Set db = CurrentDb
  
  strSQL = "SELECT SUM(tblTransaction.TxAmount + tblTransaction.TxTax) As Outstanding" _
      &amp; "FROM tblTransaction" _
      &amp; "INNER JOIN tblProduct ON tblTransaction.fkProductID = tblProduct.ProductID" _
      &amp; "INNER JOIN tblHolder ON tblProduct.fkHolderID = tblHolder.HolderID" _
      &amp; "WHERE tblTransaction.TxPaid = False" _
      &amp; "AND tlbHolder.HolderID = Me.HolderID;"
  
  DoCmd.RunSQL strSQL
  
  calcOutstanding = Outstanding
  </code></pre>
  
  <p>End Function</p>
  
  <p>The field now just shows #Error. What am I doing wrong?</p>