Formatting Issues

Fix Word DATABASE Field Codes and AutoFit Table Formatting

Emma BrownEmma Brown Oct 22, 2026 869 views

Question details

A Word DATABASE field code does not format its generated table as expected, and columns fail to autofit despite AutoFit being enabled.

How to Fix Word DATABASE Field Codes and AutoFit Table Formatting
Product
Word
Device & OS
not provided
Scenario
Generating a dynamic table from a database source using field codes and trying to ensure the columns automatically fit the content.
Observed behavior
The generated table ignores AutoFit settings, requiring manual attribute configuration using the \b and \l switches.
Before you start

Ensure your document is successfully connected to your data source. Press Alt+F9 (or Option+F9 on Mac) to reveal your document's field codes so you can edit the DATABASE syntax directly.

Solution 1Recommended

Apply the Correct \b and \l Switches for AutoFit

Combine table attributes using the \b switch and define the base table format using the \l switch to enforce AutoFit.

The \b switch applies multiple attributes to the table by adding their numeric values together. For example, the value 16 represents AutoFit, while 48 represents both AutoFit and Heading attributes combined. To ensure these attributes work, they must be paired with the \l switch, which establishes the foundational table format.

1
Reveal Field Codes

Press `Alt + F9` on your keyboard to toggle the field codes in your Word document.

2
Locate the DATABASE Field

Find the `{ DATABASE }` code block that generates your table.

3
Add Formatting Switches

Insert the `\l` and `\b` switches into the field code. To apply a standard table format with AutoFit enabled, add `\l "10" \b "16"` to the end of the syntax.

4
Verify the Complete Syntax

Your field code should look similar to this structure: `{ DATABASE \d ["Path of Database"] \c ["Query Name"] \s ["SELECT Statement"] \h \l "10" \b "16" }`.

5
Update the Field

Press `Alt + F9` to hide the field codes, then right-click the generated table (or the field area) and select 'Update Field' to apply the new formatting.

Apply the Correct \b and \l Switches for AutoFit
Combining Multiple Attributes: If you want to apply more than one table attribute at a time, simply add their numerical values together. Using \b 48 applies both the AutoFit (16) and Heading (32) properties.
Free Microsoft Office alternative

Experience Hassle-Free Formatting with WPS Office

If Microsoft Word's complex field codes and undocumented formatting switches are slowing you down, try WPS Office. It is a free, lightweight, and user-friendly alternative that provides robust table formatting tools without the steep learning curve.

  1. 1. Download the Software: Visit the official WPS website to download and install WPS Office for free.
  2. 2. Open Your Document: Launch WPS Writer and open your existing Word document. Your formatting and layouts are fully supported.
  3. 3. Edit Tables Intuitively: Use the visual table properties menu to adjust AutoFit and heading rows easily without relying on complex field code switches.
100% compatible with Microsoft Word (.doc, .docx) formatsFree and lightweight alternative to Microsoft OfficeIntuitive user interface for easy table adjustmentsBuilt-in PDF editing and easy document migration
microsoft office alternative - wps office

Frequently Asked Questions

What does the \b switch do in a Word DATABASE field?

The \b switch allows you to apply specific formatting attributes to the generated table. You can combine multiple attributes by adding their numeric values together. For example, using \b 16 applies the AutoFit attribute.

Why isn't my AutoFit working even when I use the \b switch?

The \b switch often fails to apply attributes correctly if it isn't paired with the \l switch. The \l switch defines the base format of the table. Adding both (e.g., \l "10" \b "16") usually resolves the issue.

How do I edit the field code to fix the table formatting?

To manually edit the field code, press Alt + F9 on Windows (or Option + F9 on Mac) to reveal the hidden code syntax in your document. After typing your adjustments, press Alt + F9 again and update the field.