Abundant Technologies - IT Consulting Experts

 Source Code Library

 Code Details

'Place this code on a form with a combobox called Combo1 Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer) Combo_Search Me, "Combo1", KeyCode, Shift End Sub Sub Form_load() Combo1.AddItem "Alpha" Combo1.AddItem "Beta" Combo1.AddItem "Charlie" Combo1.AddItem "Delta" Combo1.AddItem "Dingo" End Sub 'Place this code in a module Option Explicit Private Const WM_SETREDRAW = &HB Private Const KEY_A = 65 Private Const KEY_Z = 90 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 Function Combo_Search(FormName As Form, ComboName As String, 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 = FormName(ComboName).Text If Len(sTempString) = 1 Then sComboText = sTempString lReturn = SendMessage(FormName(ComboName).hwnd, WM_SETREDRAW, False, 0&) For iLoop = 0 To (FormName(ComboName).ListCount - 1) If UCase((sTempString & Mid$(FormName(ComboName).List(iLoop), _ Len(sTempString) + 1))) = UCase(FormName(ComboName).List(iLoop)) Then FormName(ComboName).ListIndex = iLoop FormName(ComboName).Text = FormName(ComboName).List(iLoop) FormName(ComboName).SelStart = Len(sTempString) FormName(ComboName).SelLength = Len(FormName(ComboName).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) FormName(ComboName).Text = sComboText FormName(ComboName).SelStart = Len(FormName(ComboName).Text) Else sComboText = sTempString End If End If Next iLoop lReturn = SendMessage(FormName(ComboName).hwnd, _ WM_SETREDRAW, True, 0&) End If End Function

Mail To: info@3pc.com