Dim Filter As String
With e.Form.Controls("设备类型")
If .Value IsNot Nothing Then
Filter = "设备类型 = '" & .Value & "'"
End If
End With
With e.Form.Controls("配件名称")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "配件名称 = '" & .Value & "'"
End If
End With
With e.Form.Controls("机车号")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "机车号 = '" & .Value & "'"
End If
End With
With e.Form.Controls("StartDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("EndDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 <= #" & .Value & "#"
End If
End With
If e.Form.Controls("yibi").Checked = True '如果闭环状态选择了"已闭"
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "配件名称 <> 待料"
End If
If e.Form.Controls("weibi").Checked = True '如果闭环状态选择了"未闭"
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "已闭 = False Or 已闭 Is Null"
End If
If Filter > "" Then
Tables("查询窗口_碎修记录").Filter = Filter
完整的代码