目录

Comparison 属性

优质
小牛编辑
123浏览
2023-12-01

全部显示

返回或设置一个 MsoFilterComparison 常量,表示如何比较 ColumnCompareTo 属性。可读写。

MsoFilterComparison 可以为下列 MsoFilterComparison 常量之一。msoFilterComparisonContainsmsoFilterComparisonEqualmsoFilterComparisonGreaterThanmsoFilterComparisonGreaterThanEqualmsoFilterComparisonIsBlankmsoFilterComparisonIsNotBlankmsoFilterComparisonLessThanmsoFilterComparisonLessThanEqualmsoFilterComparisonNotContainsmsoFilterComparisonNotEqual

expression.Comparison

expression 必需。该表达式返回“应用于”列表中的对象之一。

示例

本示例更改已有筛选,从邮件合并中删除所有 Region 域不等于“WA”的记录。

Sub SetQueryCriterion()
    Dim appOffice As Office.OfficeDataSourceObject
    Dim intItem As Integer

    Set appOffice = Application.OfficeDataSourceObject
    appOffice.Open bstrConnect:="DRIVER=SQL Server;SERVER=ServerName;" & _
        "UID=user;PWD=;DATABASE=Northwind", bstrTable:="Employees"

    With appOffice.Filters
        For intItem = 1 To .Count
            With .Item(intItem)
                If .Column = "Region" Then
                    .Comparison = msoFilterComparisonNotEqual
                    .CompareTo = "WA"
                    If .Conjunction = "Or" Then .Conjunction = "And"
                End If
            End With
        Next intItem
    End With
End Sub