Hi

I have a combo box with a list of Months however the Months are preceded with a single character code i.e
F (January)
G (February)
H (March)
J (April)
K (May)
M (June)
N (July)
Q (August)
U (September)
V (October)
X (November)
Z (December)
H (March)

As I type i need to populated the text property of the combo with a match. So if I type "J" then "J (April)" is shown however if I type "Ju" then "M (June)" will be shown.

I have accomplished this with this Function:

Public Function FindItem(sString As String, sColumn, rs As ADODB.Recordset) As String
Dim rsClone As ADODB.Recordset
Dim i As Integer

Set rsClone = rs.Clone
If sString = "" Or rsClone.RecordCount = 0 Then Exit Function

rsClone.MoveFirst

If Len(sString) = 1 Then
    rsClone.Find "[" & sColumn & "]" & " Like #" & sString & "*#"
Else
    rsClone.Find "[" & sColumn & "]" & " Like #*" & sString & "*#"
End If


If rsClone.EOF = False And rsClone.BOF = False Then
    Debug.Print rsClone(sColumn)
    FindItem= rsClone(sColumn)
    cboDropDown.ListIndex = rsClone.AbsolutePosition - 1
    rsClone.Close
    Exit Function
Else
    Debug.Print "Not Found"
End If

FindItem= ""
rsClone.Close
End Function

The problem I am having is when the cboDropDown.ListIndex is set the whole text is highlighted (see 1st Image) what I need to do is only highlight a portion of the text (see see 2nd Image).

So using the above example, if I type "J" then "J (April)" is found and only "(April)"
should be highlighted "J (April)" this will then allow me to continue to type so if I were to type "Ju" thus "M (June)" will be displayed and "ne)" highlighted.

Any suggestions?
Thanks
Darren

Attachments combobox-fullselect.jpg 3.74 KB combobox-partselect.jpg 4.19 KB

If sString is the String that you have typed then

use the following

cboDropDown.SelStart = Len(sString)
cboDropDown.SelLength = Len(cboDropDown.Text) - Len(sString)

After

..
cboDropDown.ListIndex = rsClone.AbsolutePosition - 1
...

Thanks selvaganapathy,

Will try it out on Monday.
Have a good weekend.

Darren

This article has been dead for over six months. Start a new discussion instead.