OpenDataSource Method

See Also         Example         Applies To

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

Syntax

expression.OpenDataSource(Name, Format, ConfirmConversions, ReadOnly, LinkToSource, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Connection, SQLStatement, SQLStatement1)

expression   Required. An expression that returns a MailMerge object.

Name   Required String. The data source file name. You can specify a Microsoft Query (.qry) file instead of specifying a data source, a connection string, and a query string.

Format   Optional Variant. The file converter used to open the document. Can be one of the following WdOpenFormat constants: wdOpenFormatAllWord, wdOpenFormatAuto, wdOpenFormatDocument, wdOpenFormatEncodedText, wdOpenFormatRTF, wdOpenFormatTemplate, wdOpenFormatText, wdOpenFormatUnicodeText, or wdOpenFormatWebPages. The default value is wdOpenFormatAuto.

To specify an external file format, use the OpenFormat property with a FileConverter object to determine the value to use with this argument.

ConfirmConversions   Optional Variant. True to display the Convert File dialog box if the file isn't in Word format.

ReadOnly   Optional Variant. True to open the data source on a read-only basis.

LinkToSource   Optional Variant. True to perform the query specified by Connection and SQLStatement each time the main document is opened.

AddToRecentFiles   Optional Variant. True to add the file name to the list of recently used files at the bottom of the File menu.

PasswordDocument   Optional Variant. The password used to open the data source.

PasswordTemplate   Optional Variant. The password used to open the template.

Revert   Optional Variant. Controls what happens if Name is the file name of an open document. True to discard any unsaved changes to the open document and reopen the file; False to activate the open document.

WritePasswordDocument   Optional Variant. The password used to save changes to the document.

WritePasswordTemplate   Optional Variant. The password used to save changes to the template.

Connection   Optional Variant. A range within which the query specified by SQLStatement is to be performed. How you specify the range depends on how data is retrieved. For example:

SQLStatement   Optional Variant. Defines query options for retrieving data.

SQLStatement1   Optional Variant. If the query string is longer than 255 characters, SQLStatement specifies the first portion of the string, and SQLStatement1 specifies the second portion.

Remarks

To determine the ODBC connection and query strings, set query options manually, and use the QueryString property to return the connection string. The following table includes some commonly used SQL keywords.

Keyword Description
DSN The name of the ODBC data source
UID The user logon ID
PWD The user-specified password
DBQ The database file name
FIL The file type