Table of contents
TOC
Collapse the table of content
Expand the table of content

OfficeDataSourceObject Object (Office)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Represents the mail merge data source in a mail merge operation.

Remarks

To work with the OfficeDataSourceObject object, dimension a variable as an OfficeDataSourceObject object. You can then work with the different properties and methods associated with the object. Use the SetSortOrder method to specify how to sort the records in a data source.

Example

The following example sorts the data source first according to Postal Code in descending order, then on last name and first name in ascending order.

Sub SetDataSortOrder() 
 Dim appOffice As OfficeDataSourceObject 

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

 appOffice.SetSortOrder SortField1:="ZipCode", _ 
 SortAscending1:=False, SortField2:="LastName", _ 
 SortField3:="FirstName" 
End Sub

Use the Column, Comparison, CompareTo, and Conjunction properties to return or set the data source query criterion. The following example changes an existing filter to remove from the mail merge all records that do not have a Region field equal to "WA".

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

 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

Methods

Name
ApplyFilter
Move
Open
SetSortOrder

Properties

Name
Columns
ConnectString
DataSource
Filters
RowCount
Table

See also

Other resources

Object Model Reference

© 2017 Microsoft