OfficeDataSourceObject.Columns Property (Office)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Gets an ODSOColumns object that represents the fields in a data source. Read-only.

expression .Columns

expression A variable that represents an OfficeDataSourceObject object.

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 "Field Name: " & .Item(intCount).Name 
 End With 
End Sub