ODSOFilter 对象
优质
小牛编辑
132浏览
2023-12-01
表示应用于附加的邮件合并数据源的筛选。ODSOFilter 对象为 ODSOFilters 对象的成员。
使用 ODSOFilter 对象
每个筛选为查询字符串中的一行。使用Column、Comparison、CompareTo 和Conjunction 属性返回或设置数据源查询条件。本示例更改已有筛选,从邮件合并中删除所有 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
使用 ODSOFilters 对象的Add 方法在查询中新添一个筛选条件。本示例在查询字符串中添加一行,然后将合并的筛选应用于数据源。
Sub SetQueryCriterion()
Dim appOffice As OfficeDataSourceObject
Set appOffice = Application.OfficeDataSourceObject
appOffice.Open bstrConnect:="DRIVER=SQL Server;SERVER=ServerName;" & _
"UID=user;PWD=;DATABASE=Northwind", bstrTable:="Employees"
With appOffice.Filters
.Add Column:="Region", _
Comparison:=msoFilterComparisonIsBlank, _
Conjunction:=msoFilterConjunctionAnd
.ApplyFilter
End With
End Sub
ODSOFilters ODSOFilter |