VB Code:
  1. Private Declare Function SendMessage Lib "user32" Alias _
  2.     "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
  3.     ByVal wParam As Long, lParam As Any) As Long
  4.  
  5. Const CB_FINDSTRING = &H14C
  6. Const CB_ERR = (-1)
  7.  
  8.  '*******************************************************************************
  9. ' AUTOFIND (FUNCTION)
  10. '
  11. ' DESCRIPTION:
  12. ' AUTOCOMPLETE A COMBOBOX (WORKS !!!)
  13.  '*******************************************************************************
  14.  
  15. Public Function AUTOFIND(ByRef cboCurrent As ComboBox, _
  16.     ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
  17.    
  18.     Dim lCB As Long
  19.    
  20.     Dim sFindString As String
  21.    
  22.     If KeyAscii = 8 Then
  23.        
  24.         If cboCurrent.SelStart <= 1 Then
  25.            
  26.             cboCurrent = ""
  27.            
  28.             AUTOFIND = 0
  29.            
  30.             Exit Function
  31.            
  32.         End If
  33.        
  34.         If cboCurrent.SelLength = 0 Then
  35.            
  36.             sFindString = UCase(Left(cboCurrent, Len(cboCurrent) - 1))
  37.            
  38.         Else
  39.            
  40.             sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart - 1)
  41.            
  42.         End If
  43.        
  44.     ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
  45.        
  46.         Exit Function
  47.        
  48.     Else
  49.        
  50.         If cboCurrent.SelLength = 0 Then
  51.            
  52.             sFindString = UCase(cboCurrent.Text & Chr$(KeyAscii))
  53.            
  54.         Else
  55.            
  56.             sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart) & Chr$(KeyAscii)
  57.            
  58.         End If
  59.        
  60.     End If
  61.    
  62.     lCB = SendMessage(cboCurrent.hwnd, CB_FINDSTRING, -1, ByVal sFindString)
  63.    
  64.     If lCB <> CB_ERR Then
  65.        
  66.         cboCurrent.ListIndex = lCB
  67.        
  68.         cboCurrent.SelStart = Len(sFindString)
  69.        
  70.         cboCurrent.SelLength = Len(cboCurrent.Text) - cboCurrent.SelStart
  71.        
  72.         AUTOFIND = 0
  73.        
  74.     Else
  75.        
  76.         If LimitToList = True Then
  77.            
  78.             AUTOFIND = 0
  79.            
  80.         Else
  81.            
  82.             AUTOFIND = KeyAscii
  83.            
  84.         End If
  85.        
  86.     End If
  87.    
  88. End Function