title: How can I determine the difference between typing into a combo box and selecting from a drop down in Access VBA?
body: <p>This question was asked in the <a href="https://stackoverflow.com/questions/26545974/can-access-vba-tell-the-difference-between-typing-into-a-combo-box-and-selecting/26546088#26546088">topic with a similar name</a> earlier, but the answer provided didn't really indicate HOW those events would help determine whether somebody was typing in the combo box or selecting an item in the list.  I think that it really answered the other question about how to determine when somebody was done typing, but without seeing the event handlers, I can't be sure.</p>
  
  <p>Unfortunately, I'm new here and don't have enough reputation to post a comment asking for clarification, so I have to start a new question.  Here's what I'm trying to do:</p>
  
  <p>I have a form with a combo box in the Header and, as I type in the combo box, I want the characters that I've typed to be used as a filter on the Details part of the form.  Both the combo box control source and the form's record source use the same query string.</p>
  
  <p>I've tried numerous iterations of the code below, but I can't get it to work correctly.</p>
  
  <pre><code>Private Sub cmbAppName_Change()
      Dim strApp As String
      Dim nSelStart As Integer
      Dim nSelLen As Integer
      Dim nSelected As Integer
      Dim strMsg As String
  
      On Error GoTo ERR_SUB
  
      strMsg = ""
  
      Me.cmbAppName.SetFocus
  
      ' Get current selection details
      nSelStart = Me.cmbAppName.SelStart
      nSelLen = Me.cmbAppName.SelLength
      nSelected = Me.cmbAppName.ListIndex
  
      Me.cmbAppName.SetFocus
      strApp = Nz(Me.cmbAppName.Text, "")
  
      Debug.Print "Index = " &amp; nSelected &amp; "; SelStart = " &amp; nSelStart &amp; "; SelLen = " &amp; nSelLen
      If nSelected = -1 Then
          Debug.Print "Change by typing:  " &amp; strApp
      Else
          Debug.Print "Change by list selection:  " &amp; strApp
      End If
  
      ' Get the part of the text that the user has typed
      If nSelStart &gt; 0 Then
          strApp = Left(strApp, nSelStart)
          Debug.Print "App piece = '" &amp; strApp &amp; "'"
      End If
  
      ' If there is text, set a filter (MatchAppName = InStr(strApp, datbase_column_value)
      If strApp &lt;&gt; "" Then
          Me.Filter = "MatchAppName('" &amp; strApp &amp; "', " &amp; DCApplications_Application_Col &amp; ") &gt; 0"
          Me.FilterOn = True
  '        Me.txtApplication.SetFocus
  '        Call DoCmd.FindRecord(strApp, acStart, False, acSearchAll, False, acCurrent, True)
  '        Me.cmbAppName.SetFocus
      Else
          Me.Filter = ""
          Me.FilterOn = False
      End If
  
  EXIT_SUB:
      ' Restore the selection in the combo box's text box
      Me.cmbAppName.SetFocus
      Me.cmbAppName.SelStart = nSelStart
      Me.cmbAppName.SelLength = nSelLen
      Exit Sub
  
  ERR_SUB:
      If ERR.Number = 2185 Then
          strApp = Nz(Me.cmbAppName.Value, "")
          Me.cmbAppName.SetFocus
          Debug.Print "Using " &amp; strApp
          Resume Next
      End If
  
      Me.Filter = ""
      Me.FilterOn = False
      Debug.Print ErrorMessage(ERR.Description, "cmbAppName_Change", ERR.Number, "Value = '" &amp; Me.cmbAppName.Value &amp; "'", False)
      Resume EXIT_SUB
  End Sub ' cmbAppName_Change
  </code></pre>
  
  <p>As you can see from the error handling code, I'd often get an error 2185 telling me that my control didn't have focus when using the Text property despite having a SetFocus call right before it.</p>
  
  <p>If somebody selects from the list (either by clicking or moving the selection), I'd like to go to that record, but I at least need the above piece working first.</p>