title: error 2467 when I try to refer a subform control's .Form property in vba
body: <p>ETA: I ran it past a colleague and he pointed out where the problem was. Answer at the bottom.</p>
  <p>I have a parent form setup with some invisible subform controls. Each subform control is linked to a different subform at design-time, then I have some code on the parent which flies each of the subform controls to the relevant position and makes it visible for the user to do some work with it.</p>
  <p>Here's one block of code that does this:</p>
  <pre><code>    Set Me.childRegion_MVC.Form.Recordset = rs2
      Me.childRegion_MVC.Form.cmdClearAll.Enabled = intCount &gt; 0
      Me.childRegion_MVC.Form.cmdSetAll.Enabled = intCount &lt; rs.RecordCount
  
      'Position the subform under the relevant combo box  &lt;===== requires tailoring
      Me.childRegion_MVC.Left = Me.cboRegion.Left
      Me.childRegion_MVC.Top = Me.cboRegion.Top + Me.cboRegion.Height
      Me.childRegion_MVC.Width = Me.cboRegion.Width
      Me.childRegion_MVC.Height = cintTWIPS_CM * 4.5 ' height needs to be set in twips
  
      Call Me.childRegion_MVC.Form.InitRegion   ' Ensures the subform's recordset is open and binds the subform controls
      Me.childRegion_MVC.Visible = True
      Me.childRegion_MVC.SetFocus
  </code></pre>
  <p>and here's another:</p>
  <pre><code>    Set Me.childBusiness_MVC.Form.Recordset = rs2
      Me.childBusiness_MVC.Form.cmdClearAll.Enabled = intCount &gt; 0
      Me.childBusiness_MVC.Form.cmdSetAll.Enabled = intCount &lt; rs.RecordCount
  
      'Position the subform under the relevant combo box  &lt;===== requires tailoring
      Me.childBusiness_MVC.Left = Me.cboBusiness.Left
      Me.childBusiness_MVC.Top = Me.cboBusiness.Top + Me.cboBusiness.Height
      Me.childBusiness_MVC.Width = Me.cboBusiness.Width
      Me.childBusiness_MVC.Height = cintTWIPS_CM * 4.5 ' height needs to be set in twips
  
      Call Me.childBusiness_MVC.Form.InitBusiness   ' Ensures the subform's recordset is open and bind the subform controls
      Me.childBusiness_MVC.Visible = True
      Me.childBusiness_MVC.SetFocus
  </code></pre>
  <p>My problem is that the first code block throws error 2467 (&quot;the expression you entered refers to an object that is closed or does not exist.&quot;) on the very first line at run-time (where I'm setting the Recordset using a preprepared recordset object (rs2)), whereas the second block does not.</p>
  <p>Looking at the debug window, the .Form property of the child control doesn't exist in the first case; whereas it's there in the second - so that's the proximate cause of the error, but I can't figure out <em>why</em> that form object isn't there for the first example:</p>
  <ul>
  <li>rs2 is being prepped/opened in the same way in both cases</li>
  <li>both subform controls (<code>childRegion_MVC</code> and <code>childBusiness_MVC</code>) have the same properties set in design mode</li>
  <li>both source objects (<code>subfrmRegion_MVC</code> and <code>subfrmBusiness_MVC</code> respectively) exist in the database</li>
  <li>I have compact/repaired and decompiled the database to purge any corruption issues that might have crept in.</li>
  </ul>
  <p>But <code>childRegion_MVC</code> still breaks my form when I try to use it.</p>
  <p>Can anyone suggest what might be going on here? I am utterly stumped.</p>
  <h3>+++The Solution+++</h3>
  <p>It turns out that problem was a broken recordsource on the problematic subform.</p>
  <p>This caused the subform to have an empty recordset when it was opened as part of the parent form startup and thus it promptly closed - meaning that there was no form available when my code tried to reference it later on.</p>