Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Display Ampersand "&" in Dropdown Formfield
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

The purpose of this Microsoft Word Tips & Microsoft Word Help page is to show you how you can make a legacy dropdown form field display an ampersand "&" both in the dropdown list entries and the document.

Site Note iconNote: This tips page, and the illustrations and examples were developed using Word 2003. The issue and methods displayed are fully applicable to Word 2007/2010.

Without some manipulation and a little VBA, Word will not display an ampersand "&" in a form field dropdown box or display/print the desired ampersand in the resulting form field. The cause of this behavior is explained in Microsoft Knowledge Base Article Q212101.

The KB article explains that if you use a "double" ampersand in the dropdown field options box then the ampersand will be displayed in the dropdown field.  This is true, but the ampersand is  still won't be displayed or printed in resulting formfield.

amp dd 1

amp in dd amp in dd 3

One way to work around this problem is to evaluate the value of the dropdown field on exit and use that information to set the value of an adjacent "text" form field. The text form field can be set to display the required ampersand and the dropdown field is then set to display a blank single space. The effect (to a user) is a dropdown field that displays an ampersand with the other text.

amp in dd 5

To achieve this effect, you will need a "text" form field, immediately adjacent to a "dropdown" field. Assign a meaningful bookmark name (e.g., "Sponsor" as shown below {left}) to the text form field and uncheck "Fill-in enable." Following the text form field, insert the dropdown field. Be sure to also assign a meaningful bookmark name (e.g., "SponsorDropDown" as shown below {right}) to the dropdown form field.

amp in dd 5 amp in dd 6

By setting a pair of VBA procedures to run on "Entry" to and "Exit" from the dropdown field, you can control the text displayed in the text formfield. The macro pair is shown below:

VBA Code:
Sub DDEnter()
  ActiveDocument.FormFields(("Sponsor").Result = " "
lbl_Exit::
Exit Sub
End Sub
Sub DDExit()
Dim myStringsAs String
  myString = ActiveDocument.FormFields(("SponsorDropDown").Result").Result
  Select Case ActiveDocument.FormFields(("SponsorDropDown").Result").Result").Result
    Case "AT&&T"
      ActiveDocument.FormFields(("SponsorDropDown").Result").Result").Result = " "
      ActiveDocument.FormFields(("Sponsor").Result = "AT&T"
    Case "B&&O Railroad"
      ActiveDocument.FormFields(("SponsorDropDown").Result").Result = " "
      ActiveDocument.FormFields(("Sponsor").Result = "B&O Railroad"
    Case "Johnson && Johnson"
      ActiveDocument.FormFields(("SponsorDropDown").Result").Result").Result = " "
      ActiveDocument.FormFields("Sponsor").Result = "Johnson & Johnson"
    Case Else
      ActiveDocument.FormFields("SponsorDropDown").Result = " "
      ActiveDocument.FormFields("Sponsor").Result = myString
  End Select
lbl_Exit:
Exit Sub
End Sub

'See note below
Sub AutoNew()
'Include this empty AutoOpen macro if the DD field is the first enabled
'field in the template
End Sub
Sub AutoOpen()
'Include this empty AutoOpen macro if the DD field is the first enabled
'field in the document
End Sub

TipNote iconNote: If the "text/dropdown" form field pair appear as the first field in your template/document, you could experience an error when the document opens (see example below). This Visual Basic error results because the document is opened with the focus already in the "SponsorDropDown" field. You can avoid this error by including an empty "AutoNew" and "AutoOpen" macro in the template:

The "DDEntry" macro clears the "Sponsor" field on entry to the dropdown field. After the user makes a selection and exits the dropdown field, the "DDExit" macro evaluates the selection and sets the "Sponsor" field as appropriate. The macros are set to run on entry or exit from the Dropdown Form Field Options box as shown below:

amm in dd 7

You can download a template with the required fields and macros used in this tips page demonstration here: Ampersand in DD Form Field

Site Note icon See: Installing Macros for instructions on how to set up and use the macros provided in this tips page.

That's it! I hope you have found this Microsoft Word Tips page useful and informative.

Share

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

Search my site or the web using Google Search Engine

Google Search Logo