Microsoft KB Archive/117267

{|
 * width="100%"|

WD: How to Create Ordinal (Legal) Date Formatting in FORM Fields

 * }

Q117267

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, versions 7.0, 7.0a

-

SUMMARY
This article provides two methods you can use to automatically display dates in Arabic ordinal form (sometimes referred to as legal form) in a Word for Windows FORM field.

The following are examples of dates in ordinal form (ordinal numbers indicate the order in an ordered sequence):

  23rd day of February, 1994

March 21st, 1994

Tuesday the 15th, 1994

MORE INFORMATION
Method 1 uses the \* ORDINAL field switch to format the date. The drawback to Method 1 is that no error occurs if you enter an invalid date. Method 2 uses an Entry macro in the FORM field that checks the validity of the input and then formats the date as ordinal.

Method 1: Use the \* ORDINAL field switch to format the date
Use the following steps to insert a FORM field that uses the \* ORDINAL field switch to format the date:

Note: Alternatively, you can substitute the \* ORDTEXT field switch in these instructions to format the date in ordinal text format, in which the ordinal number is spelled out rather than being expressed as a numeral (for example, "fifteenth" not "15th").

Create the Form:

Important: You must change the following settings in the Tools Options dialog box for this method to work correctly. (To do this, choose Options from the Tools menu, then select the tab listed in the Tab column below. Select or clear each setting, and then choose OK.)

Tab            Setting (On or Off) ---            --- Print           Field Codes (Off) Hidden Text (Off)

View           Hidden Text (On) Field Codes (Off)  From the Insert menu, choose Form Field. Select the Text option and then choose the Options button. From the Type list, choose Regular Text. Under Field Settings, note the name in the Bookmark box (for use in the next step), and then choose OK. Select the FORM field you inserted in step 3 above. From the Format menu, choose Font. Select Hidden Text, and then choose OK.  Press CTRL+F9 to insert field code brackets and then type the following: " \* charformat\* ordinal" Note: In place of , type the name of the FORM field bookmark you noted in step 3. </li> From the Insert menu, choose Form Field.</li> Select the Text option and then choose the Options button.</li> From the Type list, select Date.</li>  In the Date Format box, type the following case-sensitive text (be sure to include a space at the beginning of the text, between "'" and "day"), and then choose OK: "' day of 'MMMM, yyyy" If you switch to field codes view by pressing ALT+F9, you will see three fields in your document, with no spaces between any of them, as shown in the sample below: <pre class="FIXEDTEXT">      { FORMTEXT 1 }{ text1 \* ordinal }{ FORMTEXT 2 } .............. Note: The dotted line under the first field represents hidden text. </li></ol>

Fill in the Form:

Use the following instructions to fill in the form:

<ol> From the Tools menu, choose Protect Document.</li> Select the Forms option and then choose OK. Word moves the insertion point to the first FORM field.</li> In the first FORM field, type the numeric day value (a whole number from 1 through 31). For example, type 12.</li> Press TAB or ENTER to move to the next FORM field.</li> In the second FORM field, type the month and year. For example, type August, 1994 or 08/94 or aug 94.</li>  Press TAB or ENTER. If this is the last FORM field, Word moves back to the first FORM field. The text in your document looks like the following sample: <pre class="FIXEDTEXT">      12     day of August, 1994 </li>  To view the document as it will print, switch to Print Preview. Word updates the bookmark reference and does not display the results of the hidden field, so the above sample appears as follows: <pre class="FIXEDTEXT">      12th day of August, 1994 Note: If you switch to Page Layout view, the hidden FORM field result displays along with the bookmark reference field. This looks incorrect, as shown below, but the result prints correctly: <pre class="FIXEDTEXT">      1212th day of August, 1994 </li></ol>

Method 2: Use a macro
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Use the instructions below to insert a single FORM field, and attach both an Entry and Exit macro to verify and format the FORM field result in ordinal number form. This method works only if your document contains at least two FORM fields (it does not work if your document contains only one FORM field).

<ol>  Create the following two global macros, named OnEntry and OnExit, respectively:

OnEntry Macro <pre class="CODESAMP">      Sub MAIN On Error Resume Next ' INSERT THE FORM FIELD BOOKMARK NAME IN SETFORMRESULT. SetFormResult "text1", GetPrivateProfileString$("Microsoft         Word", "storevalue", "winword6.ini") SetPrivateProfileString "Microsoft Word", "storevalue", "", "WINWORD6.INI" WordRight 5, 1 err = 0 End Sub Note: The OnEntry macro checks the validity of your input (this is necessary because the DATEVALUE WordBasic command cannot read a date that contains a literal). This macro runs when Word moves the insertion point into the FORM field, before you type any input.

OnExit Macro <pre class="CODESAMP"> Sub MAIN ' INSERT THE FORM FIELD BOOKMARK NAME IN GetFormResult$. HOLD$ = GetFormResult$("TEXT1") SERIALDATE = DateValue(HOLD$) daynumber = Day(serialdate) Select Case daynumber Case 1, 21, 31 daysuffix$ = "d'st day of 'MMMM, yyyy" Case 2, 22 daysuffix$ = "d'nd day of 'MMMM, yyyy" Case 3, 23 daysuffix$ = "d'rd day of 'MMMM, yyyy" Case Else daysuffix$ = "d'th day of 'MMMM, yyyy" End Select

SetPrivateProfileString "Microsoft Word", "DateFormat", daysuffix$, "WINWORD6.INI" SetPrivateProfileString "Microsoft Word", "storevalue", hold$, "WINWORD6.INI" ' INSERT THE FORM FIELD BOOKMARK NAME IN SETFORMRESULT. SetFormResult "text1", Date$(serialdate) SetPrivateProfileString "Microsoft Word", "DateFormat", "", "WINWORD6.INI" End Sub Note: The OnExit macro runs after you type an entry in the FORM field and press TAB or ENTER. This macro formats your input as a date in ordinal form. </li> From the Insert menu, choose Form Field.</li> Select the Text option and then choose the Options button.</li> From the Type list, select Date.</li> From the Entry list, select your OnEntry macro.</li> <li>From the Exit list, select your OnExit macro, then choose OK.</li></ol>

For information about how to do this in Word 97, please see the following article(s) in the Microsoft Knowledge Base:

"Q160988 WORD 97: How To Create Ordinal (Legal) Dates In Form Fields"