Results 1 to 5 of 5

Thread: Autocomplete Combobox

Threaded View

  1. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Autocomplete Combobox

    Here is a simple example.... Create a new form and add one combo to it and paste the entire code below it to test....

    Code:
    '~~> Needs 1 Form, 1 Combobox
    
    Option Explicit
    
    '~~> API Declarations
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) _
    As Long
    
    '~~> API Constants
    Private Const CB_SELECTSTRING = &H14D
    
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
        Dim Ret As Long
        Dim sText As String
        With Combo1
            If Not (KeyAscii = vbKeyBack Or KeyAscii = vbKeyEscape Or _
            KeyAscii = vbKeyReturn) Then
                If .SelLength > 0 Then
                    sText = Left$(.Text, .SelStart) & Chr$(KeyAscii)
                Else
                    sText = .Text & Chr$(KeyAscii)
                End If
            
                Ret = SendMessage(.hwnd, CB_SELECTSTRING, -1, sText)
            
                If Ret <> -1 Then
                    .SelStart = Len(sText)
                    .SelLength = Len(.Text) - .SelStart + 1
                Else
                    .Text = sText
                    .SelStart = Len(sText) + 1
                End If
            
                KeyAscii = 0
            End If
        End With
    End Sub
    
    Private Sub Form_Load()
      '~~> Just a sample. You can add items from your table
      Combo1.Clear
      With Combo1
        .AddItem "koolsid"
        .AddItem "hack"
        .AddItem "vbfnewcomer"
        .AddItem "luca"
        .AddItem "let me in"
        .AddItem "blah blah"
        .AddItem "kool"
        .AddItem "hacker"
        .AddItem "Etc..."
      End With
    End Sub
    Hope this helps...
    Last edited by Siddharth Rout; Feb 23rd, 2009 at 08:13 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width