TableName Property

Microsoft Word Visual Basic

expression.TableName

expression    Required. An expression that returns one of the objects in the Applies To list.

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.

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
		

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.