MailMerge.OpenDataSource method

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

Namespace:  Microsoft.Office.Interop.Word
Assembly:  Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)

void OpenDataSource(
	string Name,
	ref Object Format,
	ref Object ConfirmConversions,
	ref Object ReadOnly,
	ref Object LinkToSource,
	ref Object AddToRecentFiles,
	ref Object PasswordDocument,
	ref Object PasswordTemplate,
	ref Object Revert,
	ref Object WritePasswordDocument,
	ref Object WritePasswordTemplate,
	ref Object Connection,
	ref Object SQLStatement,
	ref Object SQLStatement1,
	ref Object OpenExclusive,
	ref Object SubType
)

Parameters

Name
Type: System.String

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
Type: System.Object

Optional Object. The file converter used to open the document. Can be one of the WdOpenFormat constants. To specify an external file format, use the OpenFormat property with the FileConverter object to determine the value to use with this argument.

WdOpenFormat can be one of the following constants:

wdOpenFormatAllWord

wdOpenFormatAuto Default.

wdOpenFormatDocument

wdOpenFormatEncodedText

wdOpenFormatRTF

wdOpenFormatTemplate

wdOpenFormatText

wdOpenFormatUnicodeText

wdOpenFormatWebPages

wdOpenFormatXML

ConfirmConversions
Type: System.Object

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

ReadOnly
Type: System.Object

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

LinkToSource
Type: System.Object

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

AddToRecentFiles
Type: System.Object

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

PasswordDocument
Type: System.Object

Optional Object. The password used to open the data source. (See Remarks below.)

PasswordTemplate
Type: System.Object

Optional Object. The password used to open the template. (See Remarks below.)

Revert
Type: System.Object

Optional Object. 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
Type: System.Object

Optional Object. The password used to save changes to the document. (See Remarks below.)

WritePasswordTemplate
Type: System.Object

Optional object. The password used to save changes to the template. (See Remarks below.)

Connection
Type: System.Object

Optional Object. A range within which the query specified by SQLStatement is to be performed. (See Remarks below.) How you specify the range depends on how data is retrieved. For example:

  • When retrieving data through Open Database Connectivity (ODBC), you specify a connection string.

  • When retrieving data from Microsoft Excel using dynamic data exchange (DDE), you specify a named range.

Dynamic data exchange (DDE) is an older technology that is not secure. If possible, use a more secure alternative to DDE.

  • When retrieving data from Microsoft Access, you specify the word "Table" or "Query" followed by the name of a table or query.

SQLStatement
Type: System.Object

Optional Object. Defines query options for retrieving data. (See Remarks below.)

SQLStatement1
Type: System.Object

Optional Object. If the query string is longer than 255 characters, SQLStatement specifies the first portion of the string, and SQLStatement1 specifies the second portion. (See Remarks below.)

OpenExclusive
Type: System.Object

Optional Object. True to open exclusively.

SubType
Type: System.Object

Optional Object. Can be one of the following WdMergeSubType constants:

wdMergeSubTypeAccess

1

wdMergeSubTypeOAL

2

wdMergeSubTypeOLEDBText

5

wdMergeSubTypeOLEDBWord

3

wdMergeSubTypeOther

0

wdMergeSubTypeOutlook

6

wdMergeSubTypeWord

7

wdMergeSubTypeWord2000

8

wdMergeSubTypeWorks

4

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

Avoid using the built-in system administrator (sa) logon account. Instead, make system administrators members of the sysadmin fixed server role, and have them use their own accounts to log on. Use sa only when there is no other way to log on. To prevent unauthorized access through the sa logon account, you should assign that account a strong, unique password.

When possible, use Windows Authentication (also referred to as a trusted connection), which uses a Windows user account to connect to SQL Server. When a user connects through a Windows user account, SQL Server uses information in the Windows operating system to validate the account name and password. Before you can use Windows Authentication, a server administrator must configure SQL Server to use this mode of authentication. If Windows Authentication is not available, avoid saving users' logon information. It is more secure for users to enter their logon information each time they log on.

Avoid using hard-coded passwords in your applications. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code.

Show: