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

ODSOColumns Object (Office)

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

A collection of ODSOColumn objects that represent the data fields in a mail merge data source.

Example

Use the Columns property to return the ODSOColumns collection. The following example displays the field names in the data source attached to the active publication.

Sub ShowFieldNames() 
 Dim appOffice As OfficeDataSourceObject 
 Dim intCount As Integer 

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

 With appOffice.Columns 
 For intCount = 1 To .Count 
 MsgBox "Column Name: " & .Item(intCount).Name 
 Next 
 End With 
End Sub

Use ** Columns** ( index ), where index is the data field name or the index number, to return a single ODSOColumn object. The index number represents the position of the data field in the mail merge data source. This example retrieves the name of the first field and value of the first record of the FirstName field in the data source attached to the active publication.

Sub GetDataFromSource() 
 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.Columns 
 MsgBox "Field Name: " & .Columns(1).Name & _ 
 "Value: " & .Columns("FirstName").Value 
 End With 
End Sub

Methods

Name
Item

Properties

Name
Application
Count
Creator
Parent

See also

Other resources

Object Model Reference

© 2017 Microsoft