title: Obtaining textbox value in change event handler
body: <p>I've written a form that performs queries asynchronously <strong>as text is typed</strong> into a textbox, however I somewhat arbitrarily seem to get the following error thrown: &quot;You can't reference a property or method for a control unless the control has focus.&quot;</p>
  <p>The immediately relevant code is:</p>
  <pre><code>Dim UpdateRequested As Boolean
  Dim qryText As String
  
  .
  .
  .
  
  Private Sub txtBox_Change()
      qryText = txtBox.Text
      UpdateRequested = true
  End Sub
  </code></pre>
  <p>Some place in the ellipses is the code that handles dynamically loading an ADODB record set, populating a local table, and refreshing a sub form. However, even when I disable this code, the problem persists: Sometimes I get the error. Sometimes I do not.</p>
  <p>This seems to be persistent through closing the database and reopening it. Every time it starts working again, it's because I've been fooling around with code in the debugger, but I'm not sure what exactly is causing it to magically &quot;just work&quot; or what is causing it to not work at all.</p>
  <h1>Update</h1>
  <p>Just to make things more puzzling, I added a couple of simple event handlers:</p>
  <pre><code>Private Sub txtBox_GotFocus()
      MsgBox &quot;Got focus&quot;
  End Sub
  
  Private Sub txtBox_LostFocus()
      MsgBox &quot;Lost focus&quot;
  End Sub
  </code></pre>
  <p>I run the form. I click in the test box. I receive the &quot;Got focus&quot; message. As soon as I type I see the error as described above. If I re-open the form, I can click between the text box in question (which itself is unbound) and a bound text box in the sub form and see both &quot;Got focus&quot; and &quot;lost focus&quot; messages as one would expect. Furthermore, showing a message box with the current value of &quot;Screen.ActiveControl.Name&quot; shows the expected name just before the Text property is accessed.</p>