title: Access VBA: Changing record source of subform
body: <p>I have a form with a subform, and I want the subform record source that populates the subform to change depending on the inputs on some combo boxes in the main form. </p>
  
  <p>Using VBA, I have built a function that generates the SQL statement I want to populate the subform with. I know this works because I have tested it with the msgbox and it gives me the SQL statement I want. The sql statement uses an aggregate function so the resulting table has a different structure than the table it is querying from.</p>
  
  <p>The code I use to change the subform record source is:</p>
  
  <pre><code>me![subformname subform].form.recordsource=myfunction()
  </code></pre>
  
  <p>This has worked for me in the past, but does not work here, I simply get "#Name?" in the subform on my form. </p>
  
  <p>When I open the subform separately I get "#Name?" but when I open the Recourd Source and run the query from the record source I get a value so I am confused. </p>
  
  <p>Any ideas?</p>