Share via


OpenDataSource Method [Publisher 2003 VBA Language Reference]

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 a table from a database and denies everyone else write access to the database while it is opened. (Note that PathToFile must be replaced with a valid file path, and TableName with a valid data source table name, for this example to execute properly.)

Sub AttachDataSource()

    ActiveDocument.MailMerge.OpenDataSource _
        bstrDataSource:="PathToFile",  _
        bstrTable:="TableName", _
        fNeverPrompt:=True, fOpenExclusive:=True

End Sub

Applies to | MailMerge Object