How to create dynamic hyperlink using Field Codes in MS-Word?

4.1k Views Asked by At

I am trying to add a hyperlink to a field code in MS-Word, but I want the same field code to populate as part of a search query in the url. More relevant info below:

For Instance, this field code is linked to a form and will populate with a tracking number pulled from an inventory database «TrackingNumber», but then I want to link this generated tracking number into a url query is as follows:

HYPERLINK "https://www.google.com/searchq=«TrackingNumber»"

Is this even possible? And if so, how should I configure?

1

There are 1 best solutions below

2
On

By default, if you insert a mailmerge field into a hyperlink field, the hyperlinks will all show the first record’s address as the 'Text to display' text, even though the hyperlinks will actually point to the merged targets.

Here's how you can do get a mailmerge to display your preferred default 'Text to display' text instead:

  1. Disregarding mergefield issues for the moment, insert a hyperlink into the document in the normal way, choosing whatever 'Click Here' text you want in the 'Text to display' box.

  2. Select the inserted hyperlink and press Shift-F9 to expose its field code.

  3. Replace everything in the field between '=' and '"' with your «TrackingNumber» mergefield.

  4. Select the field and press F9 to update the display.

In Word 2007 & later, you can make the display text variable also, by following these additional steps:

  1. Position the cursor anywhere within the display text.

  2. Insert a mergefield pointing to whatever data field you want to use for the display text (this could even be the «TrackingNumber» mergefield).

  3. Delete all of the previous display text either side of your last-inserted mergefield (note that this field will likely have updated already).

  4. Execute the merge.

  5. After merging to a new document, use Ctrl-A, F9 to update all fields. Without this, the mergefield hover text won’t update to the correct targets.

Note 1: The above is only for merged output sent to a new document; it does not work with merges to email or print. For merges to email, see: https://support.microsoft.com/en-us/kb/912679

Note 2: Hyperlink fields modified this way are liable to cease functioning once the merge has been executed. Accordingly, it's best to save mailmerge main document before doing the merge and not re-save it afterwards. If you need to make changes to the mailmerge main document, don't make/save them after doing a merge; make/save them beforehand.