在访问中组合两个选项组

时间:2016-08-12 18:25:42

标签: ms-access access-vba

我有一个包含子表单和多个选项组的表单。

使用1个单选项组选择子窗体上的记录可以正常工作 但我正在尝试组合两个或更多选项组。

我将此代码用于1个选项组:

Dim strFilter As String

Select Case [Frame26]
Case 1
     'Forms!YourFormName.Form.FilterOn = False
Case 2
     'strFilter = "[YourFieldName] = 'Open - Normal' Or [YourFieldName] = 'Open - Urgent'"
     'Forms!YourFormName.Form.Filter = strFilter
     'Forms!YourFormName.Form.FilterOn = True
case3

ENZ .....

1 个答案:

答案 0 :(得分:0)

以下是实施第二个选项框架的示例:

Dim strFilter As String
Dim strFilter2 As String

Select Case [Frame26]
Case 2
     strFilter = "[YourFieldName] = 'Open - Normal' Or [YourFieldName] = 'Open - Urgent'"
case3
'............

End Select

' Add second filter - replace all your logic and fields to fit second options
Select Case [Frame<##>]
Case 2
     strFilter2 = "[YourFieldName] = 'Open - Normal' Or [YourFieldName] = 'Open - Urgent'"
case3

if strFilter = "" AND strFilter2 = "" Then
     Forms!YourFormName.Form.FilterOn = False
     Exit Sub
End If

If strFilter <> "" AND strFilter2 <> "" then
    ' Join both filters
     strFilter = "(" & strFilter & ") AND (" & strFilter2 &  ")" 
Else If strFilter2 <> "" then
     ' Just Using second filter
     strFilter = strFilter2
End if

Forms!YourFormName.Form.Filter = strFilter
Forms!YourFormName.Form.FilterOn = True