Code for combo in VB 6.0

280 pts.
Tags:
Microsoft Access
VB
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:
VB

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • 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??
            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 pointsBadges:
    report

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following