title: How can I create a control on an Access report via VBA?
body: <p>Until now, I manually created a finite number (12) of controls on a report and my code, essentially, turned them on or off (successfully) based on how many the user chose.
  Now my client wishes the user to have "no limit" to the number of controls on the report.</p>
  
  <p>My strategy is to delete the controls and create the required number on the fly (via code).
  However, when I try to create a control, I get the run-time error 2450 "cannot find the referenced form".
  Snippet:</p>
  
  <pre><code>    DoCmd.OpenReport "My_report", acViewDesign
      Dim ctl As Control
      Set ctl = CreateControl(FormName:="My_report", ControlType:=acTextBox, _
              Section:=acDetail, left:=2880, top:=0, width:=967, height:=312)
      ' ... here lies code that adjusts attributes of the controls
      DoCmd.OpenReport "My_report", acViewReport
  </code></pre>
  
  <p>Execution halts on the <code>CreateControl</code> line: ... cannot find the referenced form 'My_report'. (When working, the actual <code>CreateControl</code> code will be in a loop and geometry parameters replaced by variables.) </p>
  
  <p>All discussion I've seen relates to <em>forms</em> but the documentation at <a href="https://msdn.microsoft.com/en-us/library/office/ff836740(v=office.14).aspx" rel="nofollow">CreateControl Method</a> says the first parameter is the "name of the open form or report on which you want to create the control" so it should work for <em>reports</em> too.
  Note that the report <em>is</em> open in design mode. Any idea what I'm doing wrong?</p>