Combo Box - AutoComplete 
Author Message
 Combo Box - AutoComplete

Hi,

I was trying to use AutoComplete in a combo box.

Is there an AutoComplete (Choosing automatically a list entry after pressing
a key)?

I made a proc to select an entry, but I have a problem.

I set the ListIndex property to f.ex. 2. It displays correctly, but when I
check the value in the OnLostFocus event, the ListIndex is set back to -1.

What's wrong? I did the same in another combo box and it works fine.

Code looks like this:

  Dim a As Integer
  Dim bolFound as Boolean

  For a = 1 To cmbType.ListCount - 1
    If StrConv(cmbType.Text, vbUpperCase) = Left(cmbType.List(a), 1) Then
      cmbType.ListIndex = cmbType.ItemData(a)
      bolFound = True
      Exit For
    End If
  Next

  If Not bolFound Then
    cmbType.ListIndex = 0
  End If

  cmbType.SelStart = 0
  cmbType.SelLength = Len(cmbType.Text)

Thanks ...

M



Thu, 10 Mar 2005 13:05:36 GMT  
 Combo Box - AutoComplete
Hi again. there were some small mistakes. This is the new code:

Private Sub cmbType_Change()

  Dim a As Integer

  For a = 0 To cmbType.ListCount - 1
    If StrConv(cmbType.Text, vbUpperCase) = Left(cmbType.List(a), 1) Then
      cmbType.ListIndex = a
      bolFound = True
      Exit For
    End If
  Next

  If Not bolFound Then
    cmbType.ListIndex = 0
  End If

  cmbType.SelStart = 0
  cmbType.SelLength = Len(cmbType.Text)
  Debug.Print "Change " & cmbType.ListIndex
End Sub

Private Sub cmbType_LostFocus()

  Debug.Print "LostFocus " & cmbType.ListIndex
  Exit Sub
  If cmbType.ListIndex = -1 Then
    cmbType.ListIndex = 0
  End If

End Sub

Here is another example that works:

Private Sub cmbTitle_Change()
  Select Case cmbTitle.Text
    Case "h", "H"
      cmbTitle.ListIndex = 1
    Case "f", "F"
      cmbTitle.ListIndex = 2
    Case "l", "L"
      cmbTitle.ListIndex = 3
    Case Else
      cmbTitle.ListIndex = 0
  End Select
  cmbTitle.SelStart = 0
  cmbTitle.SelLength = Len(cmbTitle.Text)
End Sub



Thu, 10 Mar 2005 13:20:56 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Autocomplete feature with Combo Boxes.

2. Autocomplete for Combo boxes

3. VB5 Autocomplete Combo Boxes

4. enter data in a combo box based on value from another combo box

5. Limit subform combo box by selection in parent combo box

6. Want Access combo box to filter rowsource of another combo box

7. Populating a combo box from another combo box

8. Populate a combo box from another combo box selection

9. selecting records for 2nd combo box dependant on first combo box

10. Help filling second combo box from fist combo box

11. Combo box selection narrows next combo box choices

12. load 2nd combo box - depend on first combo box

 

 
Powered by phpBB® Forum Software