# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  VB6 - Auto Complete Combo Box.

## Danial

Here is little snippet I put together for a project that will give you Auto Complete feature in your Project. Simply Place a Combo Box named cmbInput and add a reference to "Microsoft Scripting Runtime". 

Note that I only used FSO to load some sample(I am loading all the folder name from C:\program files) item to the combo box, you can add any item you wish.

Finally, i am looping through all Item to find the match, if I use API it might be faster.  I will see if I can speed it up in future when I get a chance.

Enjoy


VB Code:
Option Explicit
 Private Sub cmbInput_KeyUp(KeyCode As Integer, Shift As Integer)
    AutoSel cmbInput, KeyCode
End Sub
  Private Sub Form_Load()
    
    Dim FolderPath As String
    FolderPath = "C:\Program Files"
    
    Dim Folder
    Dim File
    
    Dim FSO As New Scripting.FileSystemObject
   
    Set Folder = FSO.GetFolder(FolderPath)
    
    Dim f
    
    For Each f In Folder.SubFolders
        cmbInput.AddItem f.Name
    Next
    
End Sub
 Function AutoSel(Cmb As ComboBox, KeyCode As Integer)
    
    Debug.Print KeyCode
     If KeyCode = vbEnter Then Exit Function
    If KeyCode = 8 Then Exit Function    'Backspace
    If KeyCode = 37 Then Exit Function  'left key
    If KeyCode = 38 Then Exit Function 'up arrow key
    If KeyCode = 39 Then Exit Function  'right key
    If KeyCode = 40 Then Exit Function  'down arrow key
    If KeyCode = 46 Then Exit Function  'delete key
    If KeyCode = 33 Then Exit Function  'page up key
    If KeyCode = 34 Then Exit Function  'page down key
    If KeyCode = 35 Then Exit Function  'end key
    If KeyCode = 36 Then Exit Function  'home key
    
    
    Dim Text As String
    Text = Cmb.Text
    
    Dim i As Long
    Dim Temp As String
    
    
    For i = 0 To Cmb.ListCount
        Temp = Left(Cmb.List(i), Len(Text))
        If LCase(Temp) = LCase(Text) Then
            Cmb.Text = Cmb.List(i)
            Cmb.ListIndex = i
            Cmb.SelStart = Len(Text)
            Cmb.SelLength = Len(Cmb.List(i))
            'Cmb.SetFocus
        End If
    Next
    
End Function

----------


## ritesh9nair

Awesome!!!great work
but how to add autocomplete in textbox in vb6 from database i.e ACCESS
Hope u will reply

----------

