Private Sub txtFilter_Change() Dim strFilter As String If Me.txtFilter <> "" Then ' 获取要筛选的列名称 strFilter = Me.ActiveControl.ControlSource ' 创建过滤器条件 If IsNumeric(Me.txtFilter) Then strFilter = strFilter & " = " & Me.txtFilter Else strFilter = strFilter & " Like '" & Me.txtFilter & "'" End If ' 应用过滤器 Me.Filter = strFilter Me.FilterOn = True Else Me.FilterOn = False End If End Sub
现在,为指定的列添加自定义筛选按钮。你可以输入任何筛选条件来对该列进行筛选,如果只想显示一个值,请输入该值并按Enter键。