Article ID: 154076
Article Last Modified on 10/11/2006
Option Explicit
Private Const WM_SETREDRAW = &HB
Private Const KEY_A = 65
Private Const KEY_Z = 90
#If Win32 Then
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Long) As Long
#Else
Private Declare Function SendMessage Lib "User" ( _
ByVal hwnd As Integer, ByVal wMsg As Integer, _
ByVal wParam As Integer, lParam As Any) As Long
#End If
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim sComboText As String
Dim iLoop As Integer
Dim sTempString As String
Dim lReturn As Long
If KeyCode >= KEY_A And KeyCode <= KEY_Z Then
'only look at letters A-Z
sTempString = Combo1.Text
If Len(sTempString) = 1 Then sComboText = sTempString
lReturn = SendMessage(Combo1.hWnd, WM_SETREDRAW, False, 0&)
For iLoop = 0 To (Combo1.ListCount - 1)
If UCase((sTempString & Mid$(Combo1.List(iLoop), _
Len(sTempString) + 1))) = UCase(Combo1.List(iLoop)) Then
Combo1.ListIndex = iLoop
Combo1.Text = Combo1.List(iLoop)
Combo1.SelStart = Len(sTempString)
Combo1.SelLength = Len(Combo1.Text) - (Len(sTempString))
sComboText = sComboText & Mid$(sTempString, Len(sComboText) + 1)
Exit For
Else
If InStr(UCase(sTempString), UCase(sComboText)) Then
sComboText = sComboText & Mid$(sTempString, Len(sComboText) _
+ 1)
Combo1.Text = sComboText
Combo1.SelStart = Len(Combo1.Text)
Else
sComboText = sTempString
End If
End If
Next iLoop
lReturn = SendMessage(Combo1.hWnd, _
WM_SETREDRAW, True, 0&)
End If
End Sub
Sub Form_load()
Combo1.AddItem "Alpha"
Combo1.AddItem "Beta"
Combo1.AddItem "Charlie"
Combo1.AddItem "Delta"
Combo1.AddItem "Dingo"
End Sub
Additional query words: kbVBp400 kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport kbVBA kbControl kbintluk Combo Box ComboBox Auto Complete AutoComplete Access VBA
Keywords: kbhowto KB154076