title: Access VBA add a calculated field
body: <p>I currently have a Macro in Access that will pull in specific CSV files. I am looking to attach VBA code to this macro to also generate a calculated field at the end.</p>
  
  <p>I am able to add the calculated field manually with the expression:</p>
  
  <pre><code>IIf([Weight] &lt;= 5, 1, IIf([Weight] &lt;= 10, 2, IIf([Weight] &lt;= 20, 3, IIf([Weight] &lt;= 30, 4, IIf([Weight] &lt;= 50, 5, 6)))))
  </code></pre>
  
  <p>Is there a way to add this calculated field automatically when the macro is run, or via a second macro?</p>
  
  <p>This Access database is just being used to connect to Excel and generate PivotTables from the data. I can create the calculated fields within Excel, but cannot use calculated fields as rows in Pivottables.</p>