OfficeDataSourceObject.SetSortOrder method (Office)
Sets the sort order for mail merge data.
Syntax
expression.SetSortOrder (SortField1, SortAscending1, SortField2, SortAscending2, SortField3, SortAscending3)
expression A variable that represents an OfficeDataSourceObject object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
SortField1 | Required | String | The first field on which to sort the mail merge data. |
SortAscending1 | Optional | Boolean | True (default) to perform an ascending sort on SortField1; False to perform a descending sort. |
SortField2 | Optional | String | The second field on which to sort the mail merge data. Default is an empty string. |
SortAscending2 | Optional | Boolean | True (default) to perform an ascending sort on SortField2; False to perform a descending sort. |
SortField3 | Optional | String | The third field on which to sort the mail merge data. Default is an empty string. |
SortAscending3 | Optional | Boolean | True (default) to perform an ascending sort on SortField3; False to perform a descending sort. |
Example
The following example sorts the data source first according to Postal Code in descending order, and 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
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for