Results 1 to 3 of 3

Thread: Populating a ComboBox and associated textboxes

  1. #1

    Thread Starter
    Hyperactive Member vbuser1976's Avatar
    Join Date
    Sep 2000
    Location
    Yonkers, NY
    Posts
    404

    Question

    I have a combo box that is going to be populated with customer ID numbers. Now what I want to do is that when a user begins to enter an ID number, if the number entered has an exact match the two textboxes that I have with it should be populated automatically with the corresponding customer name and address respectively. If the number does not have a match, then I want those text boxes to be blank.

    I hope someone can help me. Any assistance would be greatly appreciated.

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    I'm not sure if this is exactly what you're looking for ... I set up a simple autocomplete combobox with two text boxes. As you type in something in the combobox, it autocompletes and automatically puts it's contents in text1 and text2 (modify this for your customer/address). If you hit backspace, it clears out the two text boxes (as will deleting the selected text in the combobox) and if you type in something that doesn't exist in the combo boxes list data, the text boxes will empty. It's a bit kludgy, but it works in this respect. The auto-complete code was found initially on Planet-source-code.com but it didn't function (it also used a timer ... buh?) but I've fixed it here. Initial credit for that part of the code goes to that author (whom I do not know the name of).

    Code:
    'This code is verified to work with VB6
    Dim BackDel As Boolean
    
    Private Sub Combobox_Change()
            FindEntry
    End Sub
    
    Private Sub ComboBox_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyBack Then BackDel = True
        If KeyAscii = vbKeyReturn Then Combobox.SelStart = Len(Combobox.Text)
    End Sub
    
    
    Private Sub Form_Load()
        With Combobox
            .AddItem "www.sluggy.com"
            .AddItem "www.slashdot.org"
            .AddItem "www.codepoet.com/UAE"
            .AddItem "www.vbworld.com"
            .AddItem "www.planet-source-code.com"
            .AddItem "www.netsync.net/users/xcalibur"
        End With
    End Sub
    
    Private Sub FindEntry()
        Dim Counter As Integer
        Dim OldLength As Integer
        
        If BackDel = True Or Combobox.Text = "" Then
            BackDel = False
            Text1.Text = ""
            Text2.Text = ""
            Exit Sub
        End If
        With Combobox
            Counter = 0
            For Counter = 0 To .ListCount
                If .Text = Left(.List(Counter), Len(.Text)) Then
                    OldLength = Len(.Text)
                    .Text = .List(Counter)
                    .SelStart = OldLength
                    .SelLength = Len(.Text) - OldLength
                    Text1.Text = .Text
                    Text2.Text = .Text
                    Else
                    If .SelLength < 1 Then
                        Text1.Text = ""
                        Text2.Text = ""
                    End If
                End If
            Next Counter
        End With
    End Sub
    For this example, add a combobox named combobox, and two textboxes, text1 and text2.

    Hope this works for ya.
    -Excalibur

  3. #3

    Thread Starter
    Hyperactive Member vbuser1976's Avatar
    Join Date
    Sep 2000
    Location
    Yonkers, NY
    Posts
    404

    Talking THANKS!

    Thanks a lot! This was just what I needed.

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