MailMergeDataSource.TableName property (Word)
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.
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.
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
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.