在访问与组合筛选工作不正常

问题描述 投票:0回答:2

我一直试图通过使用组合框来筛选SQL查询的结果。我需要用它来更新后()来完成,因为我需要它来显示所有的resutls(未过滤),然后,如果希望,过滤器基础上,组合框的内容。

这里的“Cuadro_combinado30”是组合框和“档案”的名字是我想作为筛选依据的字段的名称。

Private Sub Cuadro_combinado30_AfterUpdate()

Dim strFilter As String

With Me.Cuadro_combinado30
    If IsNull(.Value) Or .Value = "**ALL**" Then
       ' If the combo box is cleared or ALL selected, clear the form filter.
       Me.Filter = vbNullString
       Me.FilterOn = False
    Else
        ' item other than ALL is selected, filter for an exact match.
        strFilter = "[Dossier] = '" & _
            Replace(.Value, "'", "''") & "'"
        Debug.Print strFilter ' check this in Immediate window in case of 
        ' trouble you can use Ctrl+g to go to the Immediate window
        Me.Filter = strFilter
        Me.FilterOn = True
    End If
    End With

End Sub

到目前为止,结果是,当我进入的形式,所有的结果都显示,但是当我选择以过滤结果组合框的一个选项,则该查询似乎并没有找到任何如图所示没有结果。

为什么不工作的代码,我应该如何修改它的工作?

谢谢。

更新:我已经尝试过使用文本框而不是一个组合框,和它的作品,当我输入文本框的结果是基于什么我刚写的东西过滤。我想这与如何创建组合框做的,看来即使在组合框中显示的内容,过滤器上找到一个null。

ms-access combobox access-vba
2个回答
1
投票

原来的组合框具有2列,而不是一个,@Santosh解决方案完美地工作:

 Replace(.Column(1), "'", "''")

0
投票

更改组合属性一个栏需要解决的问题

© www.soinside.com 2019 - 2024. All rights reserved.