MailMerge.CreateDataSource Method
Creates a Microsoft Word document that uses a table to store data for a mail merge.
Namespace: Microsoft.Office.Interop.Word
Assembly: Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)
Syntax
'Declaration
Sub CreateDataSource ( _
ByRef Name As Object, _
ByRef PasswordDocument As Object, _
ByRef WritePasswordDocument As Object, _
ByRef HeaderRecord As Object, _
ByRef MSQuery As Object, _
ByRef SQLStatement As Object, _
ByRef SQLStatement1 As Object, _
ByRef Connection As Object, _
ByRef LinkToSource As Object _
)
'Usage
Dim instance As MailMerge
Dim Name As Object
Dim PasswordDocument As Object
Dim WritePasswordDocument As Object
Dim HeaderRecord As Object
Dim MSQuery As Object
Dim SQLStatement As Object
Dim SQLStatement1 As Object
Dim Connection As Object
Dim LinkToSource As Object
instance.CreateDataSource(Name, PasswordDocument, _
WritePasswordDocument, HeaderRecord, _
MSQuery, SQLStatement, SQLStatement1, _
Connection, LinkToSource)
void CreateDataSource(
ref Object Name,
ref Object PasswordDocument,
ref Object WritePasswordDocument,
ref Object HeaderRecord,
ref Object MSQuery,
ref Object SQLStatement,
ref Object SQLStatement1,
ref Object Connection,
ref Object LinkToSource
)
Parameters
- Name
Type: System.Object%
Optional Object. The path and file name for the new data source.
- PasswordDocument
Type: System.Object%
Optional Object. The password required to open the new data source.
- WritePasswordDocument
Type: System.Object%
Optional Object. The password required to save changes to the data source.
- HeaderRecord
Type: System.Object%
Optional Object. Field names for the header record. If this argument is omitted, the standard header record is used: "Title, FirstName, LastName, JobTitle, Company, Address1, Address2, City, State, PostalCode, Country, HomePhone, WorkPhone." To separate field names, use the list separator specified in Regional Settings in Control Panel.
- MSQuery
Type: System.Object%
Optional Object. True to launch Microsoft Query, if it's installed. The Name, PasswordDocument, and HeaderRecord arguments are ignored.
- SQLStatement
Type: System.Object%
Optional Object. Defines query options for retrieving data.
- 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.
- Connection
Type: System.Object%
Optional Object. A range within which the query specified by SQLStatement will be performed. How you specify the range depends on how data is retrieved. For example:
When retrieving data through ODBC, you specify a connection string.
When retrieving data from Microsoft Excel using dynamic data exchange (DDE), you specify a named range.
Security 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.
- LinkToSource
Type: System.Object%
Optional Object. True to perform the query specified by Connection and SQLStatement each time the main document is opened.
Remarks
The new data source is attached to the specified document, which becomes a main document if it's not one already.
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.