使用 MS Access Combobox 键入时搜索 [英] Search as you type with MS Access Combobox
问题描述
我想在 Microsoft Access 中创建一个简单的搜索组合框,如下图所示.
注意:上图来自我试图从
I would like to create a simple search-as-you-type combobox in Microsoft Access as shown in the image below.
NB: the above image is from a complicated implementation of what I am trying to achieve from here
My combobox is named ctlSearch
. Using Visual Basic, I would like to hook on to the onChange
event, detecting the user input and consequently refining the list of possible results. Is it possible to take this approach to implement the search-as-you-type combobox?
This is my Function I use to do filter combo-box as typed:
Public Sub FilterComboAsYouType(combo As ComboBox, defaultSQL As String, lookupField As String)
Dim strSQL As String
If Len(combo.Text) > 0 Then
strSQL = defaultSQL & " WHERE " & lookupField & " LIKE '*" & combo.Text & "*'"
Else
strSQL = defaultSQL 'This is the default row source of combo box
End If
combo.RowSource = strSQL
combo.Dropdown
End Sub
Set the combo-box Auto Expand property to False and call the Sub FilterComboAsYouType in Change event like this:
Private Sub cmbProductName_Change()
FilterComboAsYouType Me.cmbProductName, "SELECT * FROM Product", "ProductName"
End Sub
这篇关于使用 MS Access Combobox 键入时搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!