Range.InsertDatabase Method

Definition

Retrieves data from a data source (for example, a separate Microsoft Word document, a Microsoft Excel worksheet, or a Microsoft Access database) and inserts the data as a table in place of the specified range.

public void InsertDatabase (ref object Format, ref object Style, ref object LinkToSource, ref object Connection, ref object SQLStatement, ref object SQLStatement1, ref object PasswordDocument, ref object PasswordTemplate, ref object WritePasswordDocument, ref object WritePasswordTemplate, ref object DataSource, ref object From, ref object To, ref object IncludeFields);
abstract member InsertDatabase : obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj -> unit
Public Sub InsertDatabase (Optional ByRef Format As Object, Optional ByRef Style As Object, Optional ByRef LinkToSource As Object, Optional ByRef Connection As Object, Optional ByRef SQLStatement As Object, Optional ByRef SQLStatement1 As Object, Optional ByRef PasswordDocument As Object, Optional ByRef PasswordTemplate As Object, Optional ByRef WritePasswordDocument As Object, Optional ByRef WritePasswordTemplate As Object, Optional ByRef DataSource As Object, Optional ByRef From As Object, Optional ByRef To As Object, Optional ByRef IncludeFields As Object)

Parameters

Format
Object

Optional Object. A format listed in the Formats box in the Table AutoFormat dialog box (Table menu). Can be any of the WdTableFormat constants. A border is applied to the cells in the table by default.

Style
Object

Optional Object. The attributes of the AutoFormat specified by Format that are applied to the table. Use the sum of any combination of the following values:ValueMeaning0 (zero)None1Borders2Shading4Font8Color16Auto Fit32Heading Rows64Last Row128First Column256Last Column

LinkToSource
Object

Optional Object. True to establish a link between the new table and the data source.

Connection
Object

Optional Object. A range within which to perform the query specified by SQLStatement. 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 by using dynamic data exchange (DDE), you specify a named range or "Entire Spreadsheet."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.

SQLStatement
Object

Optional String. An optional query string that retrieves a subset of the data in a primary data source to be inserted into the document.

SQLStatement1
Object

Optional String. If the query string is longer than 255 characters, SQLStatement denotes the first portion of the string and SQLStatement1 denotes the second portion.

PasswordDocument
Object

Optional Object. The password (if any) required to open the data source. (See Remarks below.)

PasswordTemplate
Object

Optional Object. If the data source is a Word document, this argument is the password (if any) required to open the attached template. (See Remarks below.)

WritePasswordDocument
Object

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

WritePasswordTemplate
Object

Optional Object. The password required to save changes to the template. (See Remarks below.)

DataSource
Object

Optional Object. The path and file name of the data source.

From
Object

Optional Object. The number of the first data record in the range of records to be inserted.

To
Object

Optional Object. The number of the last data record in the range of records to be inserted.

IncludeFields
Object

Optional Object. True to include field names from the data source in the first row of the new table.

Remarks

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.

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.

Applies to