0

我有一个组合框,用于在 afterupdate 事件中过滤表单上的数据。以下是我一直试图用来过滤数据的查询。此代码有效地过滤数据,但我面临的问题是,当我从组合框中选择“”时,没有显示任何数据。可能出了什么问题?我该如何显示关于选择“”的表格的所有数据

Dim strCriteria As String
strCriteria = "[Jobno]='" & cboPMNO & "'"
Set rst = Me.RecordsetClone
If strCriteria = "<ALL>" Then
Me.FilterOn = False
ElseIf rst.NoMatch Then
MsgBox "No entry found"
Else
Me.FilterOn = False
Me.Filter = strCriteria
Me.FilterOn = True
End If
4

1 回答 1

0

尝试这个:

Dim strCriteria As String
strCriteria = "[Jobno]='" & Nz(cboPMNO, "<ALL>") & "'"
Set rst = Me.RecordsetClone
If strCriteria = "<ALL>" or strCriteria = "" Then
    Me.Filter = ""
    Me.FilterOn = False
ElseIf rst.NoMatch Then
    MsgBox "No entry found"
Else
    Me.Filter = strCriteria
    If Me.FilterOn = False Then Me.FilterOn = True
End If

以下是我通常会如何编写这种过滤器。我非常不喜欢消息框,除非它们是绝对必要的。在我看来,如果没有匹配项,最好只显示一个空白表单或列表框。

Dim strCriteria as String
If Nz(Me.cboPMNO, "<ALL>") <> "<ALL>" Then
    strCriteria = "[Jobno] = '" & Me.cboPMNO & "'"
End If
If strCriteria <> "" Then
    Me.Filter = strCriteria
    If Me.FilterOn = False Then Me.FilterOn = True
Else
    Me.Filter = ""
    Me.FilterOn = False
End If
于 2012-04-16T13:42:14.900 回答