|
-
Oct 10th, 2000, 08:17 AM
#1
Thread Starter
Hyperactive Member
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.
-
Oct 10th, 2000, 10:39 AM
#2
Fanatic Member
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.
-
Oct 10th, 2000, 12:20 PM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|