Share via


MailMerge.OpenDataSource Method

Publisher Developer Reference

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

Syntax

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

expression   A variable that represents a MailMerge object.

Parameters

Name Required/Optional Data Type Description
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 permission to the database. The default value is False.
fNeverPrompt Optional Long 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 a table from a database and denies everyone else write access to the database while it is opened.

For this example to run properly, you must replace PathToFile with a valid file path and TableName with a valid data source table name.

Visual Basic for Applications
  Sub AttachDataSource()
ActiveDocument.MailMerge.<strong>OpenDataSource</strong> _
    bstrDataSource:="<em>PathToFile</em>",  _
    bstrTable:="<em>TableName</em>", _
    fNeverPrompt:=True, fOpenExclusive:=True

End Sub

See Also