Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

The Database field inserts the results of a database query 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) query. You update the field to query the database again.

Security Note: 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 and file name of the database. Used for all database queries except a query to an SQL database table using ODBC. Use double backslashes in the path — for example, "C:\\Data\\Sales94.mdb".

\f "StartNumber"

Specifies the record number of the first 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 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" }

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×