Results 1 to 3 of 3

Thread: combobox autocomplete

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Question

    Hi

    How Can I an combobox that autocomplete

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    if by auto complete you mean fill itself with data
    you use the MS DataBound Combo Box form components and
    you fill in the required properties..ie database, datacontrol,recordsource, listfield, and I think datafield.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    Hi,
    I found an example on my computer that could be what you want.

    Add the following code into a module

    Code:
    Option Explicit
    
    Const CB_FINDSTRING = &H14C
    Const CB_ERR = (-1)
    
    Declare Function SendMessage Lib "user32" Alias _
                                     "SendMessageA" _
                                     (ByVal hWnd As Long, _
                                      ByVal wMsg As Long, _
                                      ByVal wParam As Long, _
                                      lParam As Any) As Long
    
    Public Function AutoFind(ByRef cboCurrent As ComboBox, _
                             ByVal KeyAscii As Integer, _
                             Optional ByVal LimitToList As Boolean = False)
            
    Dim lCB As Long
    Dim sFindString As String
    
    On Error GoTo Err_Handler
        If KeyAscii = 8 Then
            If cboCurrent.SelStart <= 1 Then
                cboCurrent = ""
                AutoFind = 0
                Exit Function
            End If
            If cboCurrent.SelLength = 0 Then
                sFindString = UCase(Left(cboCurrent, Len(cboCurrent) - 1))
            Else
                sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart - 1)
            End If
        ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
            Exit Function
        Else
            If cboCurrent.SelLength = 0 Then
                sFindString = UCase(cboCurrent.Text & Chr$(KeyAscii))
            Else
                sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart) & Chr$(KeyAscii)
            End If
        End If
        lCB = SendMessage(cboCurrent.hWnd, CB_FINDSTRING, -1, ByVal sFindString)
    
        If lCB <> CB_ERR Then
            cboCurrent.ListIndex = lCB
            cboCurrent.SelStart = Len(sFindString)
            cboCurrent.SelLength = Len(cboCurrent.Text) - cboCurrent.SelStart
            AutoFind = 0
        Else
            If LimitToList = True Then
                AutoFind = 0
            Else
                AutoFind = KeyAscii
            End If
        End If
            
    Err_Handler:
    
    End Function
    then put this into the KeyPress-event of your combobox:

    Code:
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
        KeyAscii = AutoFind(Combo1, KeyAscii, False)
    End Sub
    Hope this helps

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