Advanced Auto Complete List Combo and List Boxs

Submitted on: 2/2/2015 6:01:00 AM
By: Said Sowiny (from psc cd)  
Level: Advanced
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 1553
     This is a high class code article i never be stingy with vb lovers . I try and success to move the power of access to the power of vb . The main features are : 1) the sub can be used with combo box and list box controls. 2) High performance. 3) faster with huge lists. 4) fully support of Delete and Backspace keys. 5)Case Sensitive. 6) of course few lines of code point to the purpose. Try it and tell me. If you found this really advanced please be faithful and vote. Thanks.



Public Sub AutoCompleteList(ByVal cboCtl As ComboBox, ByVal KeyCode As Integer)

'No comments it is clear .

Dim Counter As Integer

Dim Length As Integer

If cboCtl.Text <> "" Then

If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Then

KeyCode = 0

Exit Sub

End If

For Counter = 0 To cboCtl.ListCount - 1

Length = Len(cboCtl.Text)

If Mid(cboCtl.List(Counter), 1, Len(cboCtl)) = cboCtl.Text Then

cboCtl.Text = cboCtl.List(Counter)

cboCtl.SelStart = Length

cboCtl.SelLength = Len(cboCtl.Text)

cboCtl.ListIndex = Counter

Exit For

End If


End If

End Sub


Typical usage :

Private Sub cboCategory_Change()

Call AutoCompleteList(cboCategory, mintKeyCode)

End Sub

Where mintKeyCode is a form variable given by a Form_KeyDown event like :

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

mintKeyCode = KeyCode

End Sub

and the cboCategory is the combo box filled by your own items.

Taking into consideration the header of the form should look like this one :

Option Explicit

Private mintKeyCode As Integer

and your form KeyPreview Property is set to TRUE.

Enjoy ,

Other 1 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.