Fix Word DATABASE Field Codes and AutoFit Table Formatting
Question details
A Word DATABASE field code does not format its generated table as expected, and columns fail to autofit despite AutoFit being enabled.

- 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.
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.
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.
Press `Alt + F9` on your keyboard to toggle the field codes in your Word document.
Find the `{ DATABASE }` code block that generates your table.
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.
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" }`.
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.

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. Download the Software: Visit the official WPS website to download and install WPS Office for free.
- 2. Open Your Document: Launch WPS Writer and open your existing Word document. Your formatting and layouts are fully supported.
- 3. Edit Tables Intuitively: Use the visual table properties menu to adjust AutoFit and heading rows easily without relying on complex field code switches.

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.




