280 pts.
 VB
Hi Experts in VB 6.0 Please Tell me how I code for combo just like Access form eg. In Access Form's Combo -- when we start type any letter then nearest matching data should be selected and auto also showing during typing in the combo box Question : Please give any idea for VB 6.0 Combo --- so when the typing start the comobo should be opened and nearest matched data should be selected if desired data partially selected user can press enter, the selected data should be entered in combo box with thanks Anand



Software/Hardware used:
VB
ASKED: October 16, 2009  4:26 AM
UPDATED: October 21, 2009  1:06 AM

Answer Wiki:
You will need an additional component, since vb's combo does not have that functionality. I have used the SolarWinds Auto Completion Combobox 2.1 (SWAutoCombo21IPAT.ocx), which <b>I think</b> gets installed when you install the SolarWinds free Ip Address Tracker. Here's the link to download the tool, if you want to give it a try: <a href="http://www.solarwinds.com/register/registration.aspx?program=912&c=70150000000Ehqn">Free IP Address Tracker</a> After you install it, go back to VB and from the 'Project' menu select the 'Components' option; then find and check the combo control so that it appears in the toolbox.
Last Wiki Answer Submitted:  October 16, 2009  2:28 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Try this code:

Public Sub AutoCompleteCombo(Combo1 As ComboBox, KeyAscii As Integer)
    Dim lCnt       As Long 'Generic long counter
    Dim lMax       As Long
    Dim sComboItem As String
    Dim sComboText As String 'Text currently in combobox
    Dim sText      As String 'Text after keypressed
    Dim miSelStart As Integer
    
    miSelStart = Combo1.SelStart 'Set the entry point of the selected text
    If KeyAscii = 13 Or KeyAscii = 27 Then Exit Sub 'Charage Return or escape
    
    With Combo1

        lMax = .ListCount - 1 'The number of values in the list
        sComboText = .Text 'The current text in the list
        
        '**********************************************
        'This block either removes or adds a character
        '***********************************************
        If KeyAscii = 8 Then 'Backspace
            'If there is one character left, remove the text
            If Len(Combo1.Text) = 1 Or Len(Combo1.Text) = 0 Then
                Combo1.Text = ""
                miSelStart = 0
                Exit Sub
            'There is one character and seltext (our matched text)
            ElseIf Len(Combo1.Text) - (Len(Combo1.Text) - miSelStart) = 1 Then
                Combo1.Text = ""
                miSelStart = 0
                Exit Sub
            End If
            
            'An ordinary backspace, decrement 1 character
            Combo1.Text = Left(sComboText, miSelStart - 1)
            sText = Left(sComboText, miSelStart - 1) 'reset our sText var sText = combo1.text??
        Else
            'A char other than backspace, return or escape was pressed
            sText = Left(sComboText, miSelStart) & Chr(KeyAscii) 'Increment our string with the new char
        End If

        KeyAscii = 0 'Reset key pressed
        
        '**********************************************
        'This block performs our lookup
        '**********************************************
        For lCnt = 0 To lMax
            sComboItem = .List(lCnt) 'Current item
            
            If UCase(sText) = UCase(Left(sComboItem, _
                                         Len(sText))) Then 'A match was found
                '.ListIndex = lCnt 'Not sure why this is needed
                .Text = sComboItem
                .SelStart = Len(sText) 'Start the highlighting after manually entered text
                .SelLength = Len(sComboItem) - (Len(sText)) 'Highlight to the end of the text
                
                Exit For
            Else
                .Text = sText 'Set the text value = the new text
                .SelStart = Len(.Text) 'Set selstart to the end of the string
            End If
            
        Next 'lCnt
    End With
End Sub
 1,410 pts.