Fix Word Fields to Display the First and Last Barcode Numbers
Question details
Use Word fields to display the first and last barcode sequence numbers on a page without a formula error.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A document combines SEQ, STYLEREF, and DISPLAYBARCODE fields to generate barcodes and display their sequence numbers.
- Observed behavior
- Applying a character style inside a barcode field can produce an Unexpected End of Formula error.
Open the document in desktop Word and identify the sequence name and character style used for the barcode numbers. The shortcuts below are for Word on Windows; field shortcuts may differ on other systems.
Move Styled SEQ Fields Outside DISPLAYBARCODE
Use separate sequence fields as the STYLEREF targets and repeat their values inside the barcode fields.
Create a separate SEQ field for each barcode and apply the character style to that field, not to the field nested inside DISPLAYBARCODE. The nested SEQ field uses the \c switch to repeat the preceding value without incrementing it.
On the Home tab, open the Styles pane and create a character style named SerialField, or identify the existing character style you want STYLEREF to find.
Before each barcode, press Ctrl+F9 to insert field braces and type SEQ Barcode between them. Apply the SerialField character style to the resulting SEQ field. Use the same sequence name for all related barcodes.
Place a DISPLAYBARCODE field after each separate SEQ field. Inside it, insert a nested field that repeats the preceding value, for example: { DISPLAYBARCODE { SEQ Barcode \c } CODE128 }. Use Ctrl+F9 for each pair of field braces rather than typing the braces as ordinary text.
Open the page header or footer and insert { STYLEREF SerialField } for the first styled number and { STYLEREF SerialField \l } for the last. Insert each field using Ctrl+F9.
Select the separate SEQ field results and use Home > Font to set them to 1-point white text instead of Hidden formatting. Update the fields with F9, including the header or footer fields, and check File > Print.

Edit Word Documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Its format compatibility makes everyday migration easier, though it does not fix Microsoft Word field errors and complex barcode fields should be checked after opening.

Frequently Asked Questions
Why does the barcode field show an Unexpected End of Formula error?
Applying the character style inside DISPLAYBARCODE can cause the error. Put the styled SEQ field before the barcode field and use a separate nested SEQ field with the \c switch inside DISPLAYBARCODE.
What does the SEQ \c switch do?
The \c switch repeats the closest preceding value of the named sequence instead of incrementing it. For example, use { SEQ Barcode \c } inside DISPLAYBARCODE after a separate { SEQ Barcode } field.
How does STYLEREF find the first and last numbers?
In the header or footer, insert { STYLEREF SerialField } to reference the first occurrence of the styled field on the page. Add the \l switch to reference the last occurrence: { STYLEREF SerialField \l }.
Why should I use white text instead of Hidden formatting?
The workaround uses 1-point white text for the separate styled SEQ fields rather than Hidden formatting. Set this under Home > Font, and check the result against the page background; white text is not secure or necessarily invisible.
What if the second number looks wrong on screen?
Update the fields with F9 and check File > Print. If the number appears correctly in Print Preview despite an on-screen error, the difference may be a Word display issue.




