Compartilhar via


MailMergeDataSource.TableName Property

Word Developer Reference

Returns a String with the SQL query used to retrieve the records from the data source file attached to a mail merge document. Read-only.

Syntax

expression.TableName

expression   A variable that represents a MailMergeDataSource object.

Remarks

This property may be blank if the table name is unknown or not applicable to the current data source.

Example

This example checks to see if the Customers table is the name of the table in the attached data source. If not, it attaches the Customers table in the Northwind database.

Bb224151.vs_note(en-us,office.12).gif  Note
This example uses the Visual Basic InStr function, which returns the position of the first character in the second string if it exists in the first string. A value of zero (0) is returned if the first string does not contain the second string. Setting the conditional value to less than one (1) indicates that the attached table is not named Customers.
Visual Basic for Applications
  Sub DataSourceTable()
    With ActiveDocument.MailMerge
        If InStr(1, .DataSource.TableName, "Customers") < 1 Then
            .OpenDataSource Name:="C:\ProgramFiles\Microsoft Office\Office\" & _
                "Samples\Northwind.mdb", LinkToSource:=True, _
                AddToRecentFiles:=False, Connection:="TABLE Customers"
        End If
    End With
End Sub

See Also