VB icon

AutoCompleter - Class Module

Email
Submitted on: 1/3/2015 7:53:00 PM
By: dmbbob (from psc cd)  
Level: Not Given
User Rating: By 3 Users
Compatibility: VB 5.0, VB 6.0
Views: 1365
 
     This code allows you to have an autocomplete function on any text boxes by creating an instance of the class module below and setting a text control on a form to is CompleteTextbox property. Ideal for those situations when you have multiple autocompletes. (Visual Basic 6 Only - Can easily be modified for 5.0 users)
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: AutoCompleter - Class Module
' Description:This code allows you to have an autocomplete function on any text boxes by creating an instance of the class module below and setting a text control on a form to is CompleteTextbox property. Ideal for those situations when you have multiple autocompletes. (Visual Basic 6 Only - Can easily be modified for 5.0 users)
' By: dmbbob (from psc cd)
'
' Inputs:
Dim m_objAutoCompleteUser as clsAutoComplete
Set m_objAutoCompleteUser = New clsAutoComplete
With m_objAutoCompleteUser
 .SearchList = m_strUserList
 Set .CompleteTextbox = txtUser
 .Delimeter = ","
End With
'
' Assumes:Create a new class module.
Paste all the code below into it.
Rename the module to clsAutoComplete.
'**************************************

Option Explicit
Private WithEvents m_txtComplete As TextBox
Private m_strDelimeter As String
Private m_strList As String
Private Sub m_txtComplete_KeyUp(KeyCode As Integer, Shift As Integer)
 
 Dim i As Integer
 Dim strSearchText As String
 Dim intDelimented As Integer
 Dim intLength As Integer
 Dim varArray As Variant
 
 With m_txtComplete
If KeyCode <> vbKeyBack And KeyCode > 48 Then 
 If InStr(1, m_strList, .Text, vbTextCompare) <> 0 Then
varArray = Split(m_strList, m_strDelimeter)
 
For i = 0 To UBound(varArray)
 strSearchText = Trim(varArray(i))
 
 If InStr(1, strSearchText, .Text, vbTextCompare) And
(Left$(.Text, 1) = Left$(strSearchText, 1)) And 
.Text <> "" Then
.SelText = ""
.SelLength = 0
intLength = Len(.Text)
.Text = .Text & Right$(strSearchText, Len(strSearchText) - Len(.Text))
.SelStart = intLength
.SelLength = Len(.Text)
Exit Sub
 End If
 
Next i
 End If
End If
 End With
 
End Sub
Public Property Get CompleteTextbox() As TextBox
 Set CompleteTextbox = m_txtComplete
End Property
Public Property Set CompleteTextbox(ByRef txt As TextBox)
 Set m_txtComplete = txt
End Property
Public Property Get SearchList() As String
 SearchList = m_strList
End Property
Public Property Let SearchList(ByVal str As String)
 m_strList = str
End Property
Public Property Get Delimeter() As String
 Delimeter = m_strDelimeter
End Property
Public Property Let Delimeter(ByVal str As String)
 m_strDelimeter = str
End Property


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 code (in the Not Given category)?
(The code 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 code, please click here instead.)
 

To post feedback, first please login.