OpenDataSource Method

       

Attaches a data source to the specified publication, which becomes a main publication if it's not one already.

expression.OpenDataSource(bstrDataSource, bstrConnect, bstrTable, fOpenExclusive, fNeverPrompt)

expression   Required. An expression that returns a MailMerge object.

bstrDataSource  Optional String. The data source path and file name. You can specify a Microsoft Query (.qry) file instead of specifying a data source, a connection string, and a table name string; values in a Microsoft Query file override values for bstrConnect and bstrTable.

bstrConnect  Optional String. A connection string.

bstrTable  Optional String. The name of the table in the data source.

fOpenExclusive  Optional Long. True to deny others access to the database. False allows others read/write access to the database. The default value is False.

fNeverPrompt  Optional Long. True never prompts when opening the data source. False displays the Data Link Properties dialog box. The default value is False.

Example

This example attaches the Employees table from the Northwind database and denies everyone else write access to the database while it is opened.

Sub AttachDataSource()

    ActiveDocument.MailMerge.OpenDataSource _
        bstrDataSource:="C:\Program Files\Microsoft Office" & _
        "\Office\Samples\Northwind.mdb", bstrTable:="Employees", _
        fNeverPrompt:=True, fOpenExclusive:=True

End Sub