InsertDatabase

Syntax

InsertDatabase [.Format = number] [, .Style = number] [, .LinkToSource = number] [, .Connection = text] [, .SQLStatement = text] [, .SQLStatement1 = text] [, .PasswordDoc = text] [, .PasswordDot = text] [, .DataSource = text] [, .From = text] [, .To = text] [, .IncludeFields = number]

Remarks

Retrieves data from a data source (for example, a separate Word document, a Microsoft Excel worksheet, or a Microsoft Access database) and inserts it into the active document as a table.

Argument

Explanation

.Format

Specifies a format listed under Formats in the Table AutoFormat dialog box (Table menu): 0 (zero) corresponds to the first format in the list ("none"), 1 corresponds to the second format, and so on.

.Style

Specifies which attributes of the format specified by .Format to apply to the table. Use the sum of any combination of the following values:

0 None

1 Borders

2 Shading

4 Font

8 Color

16 Auto Fit

32 Heading Rows

64 Last Row

128 First Column

256 Last Column

.LinkToSource

If 1, establishes a link between the new table and the data source.

.Connection

Specifies a range within which to perform the query. How you specify the range depends on how data is retrieved. For example:

u When retrieving data using ODBC (Windows only), you specify a connection string.

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

u When retrieving data from Microsoft Access (Windows only), you specify the word "Table" or "Query" followed by the name of a table or query.


Argument

Explanation

.SQLStatement

An optional query string that retrieves a subset of the data in a primary data source to insert into the document (Windows only).

.SQLStatement1

If the query string is longer than 255 characters, .SQLStatement specifies the first portion of the string and .SQLStatement1 specifies the second portion (Windows only).

.PasswordDoc

The password (if any) required to open the data source.

.PasswordDot

If the data source is a Word document, the password (if any) required to open the attached template.

.DataSource

The path and filename of the data source.

.From

The number of the first data record in the range of records you want to insert.

.To

The number of the last data record in the range of records you want to insert.

.IncludeFields

If 1, field names from the data source appear in the first row of the new table.


Note

To generate the connection and query strings automatically, record the actions you take in the Database dialog box (Insert menu) as a macro.

See Also

InsertExcelTable, MailMergeCreateDataSource