Share via


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)

Usage

Dim Name As String
Dim Format As Object
Dim ConfirmConversions As Object
Dim ReadOnly As Object
Dim LinkToSource As Object
Dim AddToRecentFiles As Object
Dim PasswordDocument As Object
Dim PasswordTemplate As Object
Dim Revert As Object
Dim WritePasswordDocument As Object
Dim WritePasswordTemplate As Object
Dim Connection As Object
Dim SQLStatement As Object
Dim SQLStatement1 As Object
Dim OpenExclusive As Object
Dim SubType As Object
Dim mailMerge1 As MailMerge
mailMerge1.OpenDataSource(Name, Format, ConfirmConversions, ReadOnly, LinkToSource, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Connection, SQLStatement, SQLStatement1, OpenExclusive, SubType)

Syntax

Sub OpenDataSource( _
    <InAttribute()> ByVal Name As String, _
    <InAttribute()> Optional ByRef Format As Object, _
    <InAttribute()> Optional ByRef ConfirmConversions As Object, _
    <InAttribute()> Optional ByRef ReadOnly As Object, _
    <InAttribute()> Optional ByRef LinkToSource As Object, _
    <InAttribute()> Optional ByRef AddToRecentFiles As Object, _
    <InAttribute()> Optional ByRef PasswordDocument As Object, _
    <InAttribute()> Optional ByRef PasswordTemplate As Object, _
    <InAttribute()> Optional ByRef Revert As Object, _
    <InAttribute()> Optional ByRef WritePasswordDocument As Object, _
    <InAttribute()> Optional ByRef WritePasswordTemplate As Object, _
    <InAttribute()> Optional ByRef Connection As Object, _
    <InAttribute()> Optional ByRef SQLStatement As Object, _
    <InAttribute()> Optional ByRef SQLStatement1 As Object, _
    <InAttribute()> Optional ByRef OpenExclusive As Object, _
    <InAttribute()> Optional ByRef SubType As Object _
)
void OpenDataSource(
    [In] string Name, 
    [In, Optional] ref object Format, 
    [In, Optional] ref object ConfirmConversions, 
    [In, Optional] ref object ReadOnly, 
    [In, Optional] ref object LinkToSource, 
    [In, Optional] ref object AddToRecentFiles, 
    [In, Optional] ref object PasswordDocument, 
    [In, Optional] ref object PasswordTemplate, 
    [In, Optional] ref object Revert, 
    [In, Optional] ref object WritePasswordDocument, 
    [In, Optional] ref object WritePasswordTemplate, 
    [In, Optional] ref object Connection, 
    [In, Optional] ref object SQLStatement, 
    [In, Optional] ref object SQLStatement1, 
    [In, Optional] ref object OpenExclusive, 
    [In, Optional] ref object SubType
);
public: Void OpenDataSource(
    String^ Name, 
    &Object^ Format, 
    &Object^ ConfirmConversions, 
    &Object^ ReadOnly, 
    &Object^ LinkToSource, 
    &Object^ AddToRecentFiles, 
    &Object^ PasswordDocument, 
    &Object^ PasswordTemplate, 
    &Object^ Revert, 
    &Object^ WritePasswordDocument, 
    &Object^ WritePasswordTemplate, 
    &Object^ Connection, 
    &Object^ SQLStatement, 
    &Object^ SQLStatement1, 
    &Object^ OpenExclusive, 
    &Object^ SubType
);
public void OpenDataSource(
    /*in*/System.String Name, 
    /*in*/System.Object Format, 
    /*in*/System.Object ConfirmConversions, 
    /*in*/System.Object ReadOnly, 
    /*in*/System.Object LinkToSource, 
    /*in*/System.Object AddToRecentFiles, 
    /*in*/System.Object PasswordDocument, 
    /*in*/System.Object PasswordTemplate, 
    /*in*/System.Object Revert, 
    /*in*/System.Object WritePasswordDocument, 
    /*in*/System.Object WritePasswordTemplate, 
    /*in*/System.Object Connection, 
    /*in*/System.Object SQLStatement, 
    /*in*/System.Object SQLStatement1, 
    /*in*/System.Object OpenExclusive, 
    /*in*/System.Object SubType
);
function OpenDataSource(
     Name : String, 
     Format : Object, 
     ConfirmConversions : Object, 
     ReadOnly : Object, 
     LinkToSource : Object, 
     AddToRecentFiles : Object, 
     PasswordDocument : Object, 
     PasswordTemplate : Object, 
     Revert : Object, 
     WritePasswordDocument : Object, 
     WritePasswordTemplate : Object, 
     Connection : Object, 
     SQLStatement : Object, 
     SQLStatement1 : Object, 
     OpenExclusive : Object, 
     SubType : Object
);

Parameters

  • 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 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
    Optional Object. True to display the Convert File dialog box if the file isn't in Microsoft Word format.
  • ReadOnly
    Optional Object. True to open the data source on a read-only basis.
  • LinkToSource
    Optional Object. True to perform the query specified by Connection and SQLStatement each time the main document is opened.
  • AddToRecentFiles
    Optional Object. True to add the file name to the list of recently used files at the bottom of the File menu.
  • PasswordDocument
    Optional Object. The password used to open the data source. (See Remarks below.)
  • PasswordTemplate
    Optional Object. The password used to open the template. (See Remarks below.)
  • Revert
    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
    Optional Object. The password used to save changes to the document. (See Remarks below.)
  • WritePasswordTemplate
    Optional object. The password used to save changes to the template. (See Remarks below.)
  • Connection
    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
    Optional Object. Defines query options for retrieving data. (See Remarks below.)
  • SQLStatement1
    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
    Optional Object. True to open exclusively.
  • SubType
    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

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

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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000

Target Platforms

See Also

Reference

MailMerge Interface
Microsoft.Office.Interop.Word Namespace

Other Resources

MailMerge Members