您可以創建一個ComboBox,用於在鍵入時過濾記錄集。當您搜索與您正在查找的內容類似的記錄時,這非常有用,但可能不完全匹配!
按Alt + F11並右鍵單擊您之前創建的表單。粘貼在下面的腳本中。
[![Option Compare Database
Private Sub ComboSelect_Change()
' You need to use String delimiters if you want to use a Text Field like:
' Me.Filter "\[ATextFieldInRecordSource\] = """ & Me.FilterComboBox & """"
' For a Numeric Field, use something like this:
' Me.Filter "\[ANumericFieldInRecordSource\] = " & Me.FilterComboBox
' Me.FilterOn = True
Me.\[Customer_Query subform1\].Form.Filter = "\[Company_Name\] Like '*" &
Replace(Me.ComboSelect.Text, "'", "''") & "*'"
Me.\[Customer_Query subform1\].Form.FilterOn = True
End Sub][1]][1]
Notice a few things:
• The subform is named Customer_Query subform1’
• The combobox is named ComboSelect’
• Finally, the ‘like clause’ is used in combination with the wildcard character.
• Like '*" & Replace(Me.ComboSelect.Text, "'", "''") & "*'"
當您在組合框中鍵入文本時,會動態地重新查詢子窗體中的結果。
感謝您提供非常有用的建議,它效果很好 – Royy