The information in this article applies to:
- Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
- Microsoft Word for Windows 95, 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
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:
<Bookmark Name> \* charformat\* ordinal
Note: In place of <Bookmark Name>, type the name of the FORM
field bookmark you noted in step 3.
From the Insert menu, choose Form Field.
Select the Text option and then choose the Options button.
From the Type list, select Date.
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:
{ FORMTEXT 1 }{ text1 \* ordinal }{ FORMTEXT 2 }
..............
Note: The dotted line under the first field represents
hidden text.
Fill in the Form:
Use the following instructions to fill in the form:
- From the Tools menu, choose Protect Document.
- Select the Forms option and then choose OK. Word moves the
insertion point to the first FORM field.
- In the first FORM field, type the numeric day value (a whole
number from 1 through 31). For example, type "12" (without the
quotation marks).
- Press TAB or ENTER to move to the next FORM field.
- In the second FORM field, type the month and year. For
example, type "August, 1994" or "08/94" or "aug 94" (without
the quotation marks).
- 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:
12 day of August, 1994
- 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:
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:
1212th day of August, 1994
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).
- Create the following two global macros, named OnEntry and
OnExit, respectively:
OnEntry Macro
-------------
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
------------
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.
- From the Insert menu, choose Form Field.
- Select the Text option and then choose the Options button.
- From the Type list, select Date.
- From the Entry list, select your OnEntry macro.
- From the Exit list, select your OnExit macro, then choose OK.
For information about how to do this in Word 97, please see the following
article(s) in the Microsoft Knowledge Base:
ARTICLE-ID: Q160988
TITLE : WORD 97: How To Create Ordinal (Legal) Dates In Form Fields
REFERENCES
"Microsoft Word User's Guide," version 6.0, pages 309-310, 317-318, 326
Kbcategory: kbusage kbmacro kbhowto
KBSubcategory: kbfield
|