This documentation is archived and is not being maintained.

MailMergeDataSources.Item Method

Office 2007
Returns the MailMergeDataSource object at the specified index position in the MailMergeDataSources collection.

Version Information
 Version Added:  Publisher 2007

Syntax

expression.Item(varIndex)

expression   A variable that represents a MailMergeDataSources collection.

Parameters

NameRequired/OptionalData TypeDescription
varIndexRequiredVariantThe index number or name of the object to return.

Return Value
MailMergeDataSource

Remarks

The Item method is the default member of the MailMergeDataSources collection

If there is only a single MailMergeDataSource object in the active document, the MailMergeDataSources collection is empty. In that case, if you try to use the DataSources property of the MailMergeDataSource object to get the data sources collection, Microsoft Office Publisher returns an error.

Example

The following Microsoft Visual Basic for Applications (VBA) macro shows how to get the names of all the connected data sources in the MailMergeDataSources collection in the active document. It uses the IsDataSourceConnected property of the active document to determine if a data source is connected.

If one or more data sources is connected, the macro uses the Count property of the MailMergeDataSources collection to determine how many data sources are connected.

If just one data source is connected, the macro prints the name of that data source in the Immediate window; if more than one data source is connected, the macro uses the Item method of the MailMergeDataSources collection to iterate through the collection and the Name property of the MailMergeDataSource object to print the name of each connected data source in the Immediate window.

Visual Basic for Applications
Public Sub Item_Example()

    Dim pubMailMergeDataSources As Publisher.MailMergeDataSources
    Dim pubMailMergeDataSource As Publisher.MailMergeDataSource
    Dim lngCount As Long
    Dim intCounter As Integer
    
    If ThisDocument.IsDataSourceConnected Then
    
        Set pubMailMergeDataSources = ThisDocument.MailMerge.DataSource.DataSources
        
        lngCount = pubMailMergeDataSources.Count
        
        If lngCount > 1 Then

            ' More than one data source is connected.        
            For intCounter = 1 To lngCount
                Debug.Print pubMailMergeDataSources.Item(intCounter).Name
            Next
        
        Else
        				
            ' Only one data source is connected.
            Set pubMailMergeDataSource = ThisDocument.MailMerge.DataSource
            Debug.Print "Only one data source ("; pubMailMergeDataSource.Name; ") is connected."
        
        End If
        
    Else
    
        Debug.Print "No data sources are connected."
    
    End If
    
End Sub



Show: