Results 1 to 6 of 6

Thread: Results as you type in a ComboBox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2001
    Location
    Southern California
    Posts
    733

    Results as you type in a ComboBox

    How can you get the combo box to display data in the drop down according to what characters are typed in?

    Thanks,
    Jeff

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2001
    Location
    Southern California
    Posts
    733
    As you type in characters, if they match what is in the drop down box. How do you get this to happen?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2001
    Location
    Southern California
    Posts
    733
    anyone got any ideas?

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Set the style to 2- Dropdown List and set the Sorted property equal to True.

  5. #5

  6. #6
    Addicted Member E-Link's Avatar
    Join Date
    Nov 2001
    Location
    INA
    Posts
    242
    Try This ..

    VB Code:
    1. Public Function FindString(partial As String, Kontrol As ComboBox) As String
    2. Dim i As Integer
    3. For i = 0 To Kontrol.ListCount
    4.     If partial = UCase(Mid(Kontrol.List(i), 1, Len(partial))) Then
    5.         FindString = Right(Kontrol.List(i), Len(Kontrol.List(i)) - Len(partial))
    6.        
    7.     End If
    8.    
    9. Next
    10. End Function
    11.  
    12. Public Sub autocomplete(Kontrol As ComboBox, KeyAscii As Integer)
    13. Dim Data As String
    14. Dim Dapat As String
    15. If Kontrol.Text <> "" Then Data = Mid(Kontrol.Text, 1, Kontrol.SelStart)
    16. If Kontrol.SelLength = Len(Kontrol.Text) Then Kontrol.Text = ""
    17. If KeyAscii <> 13 And KeyAscii <> vbKeyBack Then
    18.     Data = CStr(Data) + Chr(KeyAscii)
    19. Else
    20.     If KeyAscii = vbKeyBack And Data <> "" Then
    21.         Data = Mid(Data, 1, Len(Data) - 1)
    22.     Else
    23.        
    24.         Exit Sub
    25.     End If
    26. End If
    27.  
    28. Dapat = FindString(UCase$(Data), Kontrol)
    29.  
    30. Kontrol.Text = Data
    31. Kontrol.SelStart = Len(Data)
    32. Kontrol.SelText = Dapat
    33.  
    34. Kontrol.SelStart = Len(Data)
    35. Kontrol.SelLength = (Len(Kontrol.Text) - Len(Data)) + 1
    36.  
    37. End Sub
    38.  
    39.  
    40.  
    41. Private Sub Combo1_KeyPress(KeyAscii As Integer)
    42. autocomplete Combo1, KeyAscii
    43. KeyAscii = 0
    44. End Sub

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