View Single Post
 
Old 08-19-2024, 04:06 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,383
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You've posted this question as a mailmerge topic, but your field code refers to a REF field, not a mailmerge field.

Word cannot format numeric values having more than 15 significant digits. With some field math, though, you could use a field code to evaluate the number's order of magnitude and prefix the mergefield's unformatted output with the required number of 0s.

Assuming you're using a mailmerge, if your source data contains the leading 0s (and is not just formatted to display leading 0s), a simple approach would be to create a dummy first record with some random text in that field. That way, the mailmerge will treat the data as text and output it with the leading 0s.

Otherwise, you can use some field math in another field to determine the data field's order of magnitude and, from that, the number of leading 0s to output. For example, using an ASK field to demonstrate the process:
Code:
{QUOTE↵
{ASK a "Input the raw number"}↵
{=a<10^17 \# "'0';;"}{=a<10^16 \# "'0';;"}{=a<10^15 \# "'0';;"}{=a<10^14 \# "'0';;"}{=a<10^13 \# "'0';;"}{=a<10^12 \# "'0';;"}{=a<10^11 \# "'0';;"}{=a<10^10 \# "'0';;"}{=a<10^9 \# "'0';;"}{=a<10^8 \# "'0';;"}{=a<10^7 \# "'0';;"}{=a<10^6 \# "'0';;"}{=a<10^5 \# "'0';;"}{=a<10^4 \# "'0';;"}{=a<10^3 \# "'0';;"}{=a<10^2 \# "'0';;"}{=a<10^1 \# "'0';;"}}{REF a}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. Instead of the ↵ symbols, you should use real line breaks.

For a macro to convert the above field code representation into a working field code, see Convert Text Representations of Fields to Working Fields in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote