Access2016-VBA代码-FilterOn-多个条件-无法工作

问题描述

我有一个带有组合框的主表单,用于过滤子表单。

我希望基于组合框中的条目对子表单中的信息进行过滤。

对于我的一生,我无法使它起作用:

Private Sub CMBOwner_AfterUpdate()
Dim strWhere As String
Dim lngLen As Long
strWhere = ""

'Look at each search Box,and build up the criteria string from the non-blank ones.
'LocationName Field
If Not IsNull(Me.CMBLocationID) Then
     strWhere = strWhere & "[InventoryLocationID] = " & Me.CMBLocationID
     Else
     strWhere = strWhere & "[InventoryLocationID] = '" & "'"
End If

'Owner Field
If Not IsNull(Me.CMBOwner) Then
        If strWhere <> "" Then
        strWhere = strWhere & " AND [fkOwner] = " & Me.CMBOwner
        Else
        strWhere = strWhere & "[fkOwner] = " & Me.CMBOwner
        End If
End If


'SupplyName Field
If Not IsNull(Me.CMBAssetName) Then
        If strWhere <> "" Then
        strWhere = strWhere & " AND [fkSupplyID] = " & Me.CMBAssetName
        Else
        strWhere = strWhere & "[fkSupplyID] = " & Me.CMBAssetName
        End If
End If



If Len(strWhere) <= 0 Then 'There was nothing in the string
    Exit Sub
Else 'There is something,so remove "AND" at the end.
    'For debugging,remove the leading quote on the next line.  Prints to Imediate Window (Ctrl+G)
Debug.Print strWhere

    'Finally,apply the string as the form's Filter.
[Forms]![FrmTransSupplySummary]![QrySupplyTransDS].Form.Filter = strWhere
[Forms]![FrmTransSupplySummary]![QrySupplyTransDS].Form.FilterOn = True
End If

End Sub

当我按原样进行调试打印并且所有组合框都设置为“”时,它表示:

[InventoryLocationID] = 6 AND [fkOwner] = AND [fkSupplyID] =

运行“ OnFilter = True”的代码行时,我得到一个错误

如果我将组合框设置为以0开头,则过滤器有效,但不返回任何内容。因为没有任何物品的零值。

我需要什么更正才能使公式起作用?

谢谢 塔米(Tammy)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)