i would like to make a search textbox that will automatically searchh the data and droping down the txtbox... like in the member search of this site...

pleaseeeeeeee.. kindly give me some code.. to make that...
sorry for the previous thread.


10 Years
Discussion Span
Last Post by jonc

I understand what you mean, like an autocomplete text field so as you're typing, it will attempt to finish off what you're typing to the nearest match?

I have found something on another site, but as I'm unsure that I can link to an external forum, I'll quote it from the other site but won't direct link.

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.


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
      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))
              End If

      End Function

Hope that is what you're after :)

Votes + Comments
thxxxx for alwayzzzzz helping me... alwayzz present dude ah..^_^

theirs an error on this code..

actually i use ms access on my database..
could any one post any suggestion.



Oh, you're using Access (VBA) rather than VB6?
I didn't know this when posting... the source I found on the site (and quoted above) was for actual VB6 which would explain your problem.

One thing to check though... have you added the reference to "Microsoft Scripting Runtime" in your database?
The following quoted line of code is attempting to create a new instance of an FSO object, but it will fail if the reference is not made to the DLL which holds this object.

Dim FSO As New Scripting.FileSystemObject

Info you may not need but I've included to be on the safe side :)
If I remember right, when in Access, open up any code module (an actual module or the code window for a form) and go to "Tools" menu at the top and then "References". You would need to ensure that the Scripting runtime one is ticked before anything with FSO/FileSystemObjects will work.


owss. im sorry. i did wrong.^_^
hehe... i miss that thing..

thxxxxxx a lot..

actually i use vb6 in my project but i only use access in my database ..if im not wrong.
actually i get the exact code.. but the code are to more..
they use the module for it..

thxxxxxxxx a lot..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.