Code for combo in VB 6.0

Microsoft Access
Visual Basic
Visual Basic 6
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:

Answer Wiki

Thanks. We'll let you know when a new response is added.

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 I think 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: Free IP Address Tracker

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.

Discuss This Question: 1  Reply

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Vatchy
    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??
                '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
                    .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,415 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: