MailMerge.OpenDataSource Method

Definition

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

public 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);
abstract member OpenDataSource : string * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj -> unit
Public Sub OpenDataSource (Name As String, Optional ByRef Format As Object, Optional ByRef ConfirmConversions As Object, Optional ByRef ReadOnly As Object, Optional ByRef LinkToSource As Object, Optional ByRef AddToRecentFiles As Object, Optional ByRef PasswordDocument As Object, Optional ByRef PasswordTemplate As Object, Optional ByRef Revert As Object, Optional ByRef WritePasswordDocument As Object, Optional ByRef WritePasswordTemplate As Object, Optional ByRef Connection As Object, Optional ByRef SQLStatement As Object, Optional ByRef SQLStatement1 As Object, Optional ByRef OpenExclusive As Object, Optional ByRef SubType As Object)

Parameters

Name
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
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:wdOpenFormatAllWordwdOpenFormatAuto Default.wdOpenFormatDocumentwdOpenFormatEncodedTextwdOpenFormatRTFwdOpenFormatTemplatewdOpenFormatTextwdOpenFormatUnicodeTextwdOpenFormatWebPageswdOpenFormatXML

ConfirmConversions
Object

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

ReadOnly
Object

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

LinkToSource
Object

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

AddToRecentFiles
Object

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

PasswordDocument
Object

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

PasswordTemplate
Object

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

Revert
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
Object

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

WritePasswordTemplate
Object

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

Connection
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
Object

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

SQLStatement1
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
Object

Optional Object. True to open exclusively.

SubType
Object

Optional Object. Can be one of the following WdMergeSubType constants:wdMergeSubTypeAccess 1wdMergeSubTypeOAL 2wdMergeSubTypeOLEDBText 5wdMergeSubTypeOLEDBWord 3wdMergeSubTypeOther 0wdMergeSubTypeOutlook 6wdMergeSubTypeWord 7wdMergeSubTypeWord2000 8wdMergeSubTypeWorks 4

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.

DSNThe name of the ODBC data source
UIDThe user logon ID
PWDThe user-specified password
DBQThe database file name
FILThe 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.

Applies to