0

I have populated a ComboBox with a list of strings and since that list is pretty long, I'm struggling to add an Auto-Complete feature like to the ComboBox who will display matching strings as the user types in characters.

An idea of what I want can be found here Auto-Complete with only text and not numbers ComboBox Excel VBA but it's done using VBA Excel.

Here is the code I got so far

Private Sub ComboBox1_Click()
    Dim i As Long
    Static found As Boolean

    If found Then
        found = False
        Exit Sub
    End If

    With FormDialog.ComboBox1
        .DropDown
        '.MatchEntry = fmMatchEntryFirstLetter
        If .Text = "" Then Exit Sub
        For i = 0 To .ListCount
            If InStr(.List(i), .Text) > 0 Then
                found = True
                If found Then
                    ' the suggestion code will go here I think
                End If
                Exit For '<--| exit loop
            End If
        Next i
    End With
End Sub

If anyone can help me with this, I will be thankful.

Stackgeek
  • 227
  • 1
  • 12
  • What's the difference between `MatchEntry = fmMatchEntryComplete` and the action you wish to create with your macro? – Variatus Aug 02 '17 at 10:18
  • `fmMatchEntryComplete` does not display a dropdown of matching characters but select the matching string directly and in the written order in the list. The code above actually is doing kind of the same and that's why I'm asking for help. – Stackgeek Aug 02 '17 at 10:59
  • Sorry. Did you answer my question? If you only want to see what you typed you should set `frmMatchEntryNone`. – Variatus Aug 02 '17 at 12:04
  • Yes I hope so. Maybe I didn't get your point well ? @Variatus – Stackgeek Aug 02 '17 at 12:06
  • I'm asking what the code is supposed to do that none of the three choices for the `MatchEntry` property can do. – Variatus Aug 02 '17 at 12:07
  • the only thing that is excel related in the original post, is the code Button3_click. it fills the data into the combobox. (that could be put into the form init code ... the form code itself should work in Word. it does not interact with Excel at all – jsotola Aug 03 '17 at 07:54
  • Thank you @jsotola I've tried it but It isn't working. But I get the logic from there and still trying to make it work. – Stackgeek Aug 03 '17 at 11:19
  • I have figured it out. It works. thank you @jsotola In fact the form code itself do the work but it has to be adapted. – Stackgeek Aug 03 '17 at 11:58

1 Answers1

0

Following @jsotola comment, I've found after trials that the kind of answer provided here Auto-Complete with only text and not numbers ComboBox Excel VBA by @Ralph is useful to answer my question. You have to only focus on the txtSearchTerm_Change() method and adapt it to your program requirements.

Don't forget the Option Compare Text at the beginning to disbale case sensitivity on the search.

I hope it helps.

Stackgeek
  • 227
  • 1
  • 12