Field codes: Database field

The Database field inserts the results of a database query (query: A means of finding all the records stored in a data source that fit a set of criteria you name. Queries can contain operators, quotation marks, wildcard characters, and parentheses to help focus your search.) in a Word table. If the number of columns is 62 or greater, the Database field inserts the results of a query in columns separated by tabs. The Database field contains all the information needed to connect to a database and perform a Structured Query Language (SQL) (Structured Query Language (SQL): A database query and programming language widely used for accessing, querying, updating, and managing data in relational database systems.) query. You update the field to query the database again.

Security  When you connect to a data source, be sure that your password is not readable by others. For example, do not store it where it is readable as plain text, such as in a macro. Do not send it on the Internet unless you use the Secure Sockets Layer (SSL) protocol, which encrypts data. You can tell whether a Web address uses SSL if the address starts with "https" instead of "http."

Syntax

When you view the Database field code in your document, the syntax looks like this:

{ DATABASE [Switches ] }

 Note    A field code tells the field what to show. Field results are what is shown in the document after having evaluated the field code. To toggle between viewing the field code and the field code results, press Alt+F9.

Switches

\b "Sum"

Specifies which attributes of the format set by the \l switch to apply to the table. If the \l switch is blank, the \b switch value must be 16 (AutoFit). Include the sum of any combination of the following values to specify the value for the switch.

For example, the switches \l "3" \b "11" apply only the borders, shading, and color attributes of the table format set by the \l switch.

This value Specifies
0 None
1 Borders
2 Shading
4 Font
8 Color
16 AutoFit
32 Heading Rows
64 Last Row
128 First Column
256 Last Column

\c "ConnectInfo"

Specifies a connection to the data. For example, a query to a Microsoft Office Access database might contain the connection instructions \c "DSN=MS Access Databases; DBQ=C:\\Data\\Sales93.mdb; FIL=RedISAM;".

\d "Location"

The path (path: The route that the operating system uses to locate a folder or file; for example, C:\House finances\March.doc.) and file name of the database. Used for all database queries except a query to an SQL database table using ODBC (Open Database Connectivity (ODBC): A standard method of sharing data between databases and programs. ODBC drivers use the standard Structured Query Language (SQL) to gain access to external data.). Use double backslashes in the path — for example, "C:\\Data\\Sales94.mdb".

\f "StartNumber"

Specifies the record number of the first data record (data record: A complete set of related information that corresponds to one row of information in the data source. All information about one client in a client mailing list is an example of a data record.) to insert — for example, \f "2445".

\h

Inserts field names from the database as column headings in the resulting table.

\l "Format#"

Applies a format from the Table AutoFormat dialog box to the result of the database query. The number Format# is determined by the table format that you select in the dialog box. If this switch is used and the \b switch doesn't specify the table attributes, Word inserts an unformatted table.

\o

Inserts data at the beginning of a merge.

\s "SQL"

SQL instructions. You must insert a backslash (\) before each quotation mark in the instructions. For example, instructions for an Access database might be as follows:
"select * from \s \"Customer List\"".

\t "EndNumber"

Specifies the record number of the last data record to insert — for example: \t "2486".

Examples

The following field results from a query to an Access database through ODBC (Open Database Connectivity (ODBC): A standard method of sharing data between databases and programs. ODBC drivers use the standard Structured Query Language (SQL) to gain access to external data.) using the Database command:

{ DATABASE \d "C:\\Data\\Sales93.mdb" \c "DSN=MS Access Database; DBQ=C:\\Data\\Sales93.mdb; FIL=RedISAM" \s "select * from \"Customer List\" " \f "2445" \t "2486" \l "2" }

 
 
Applies to:
Word 2013, Word 2010, Word 2007