WD: How to Create Ordinal (Legal) Date Formatting in FORM Fields |
Q117267
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
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.
Tab Setting (On or Off)
--- -------------------
Print Field Codes (Off)
Hidden Text (Off)
View Hidden Text (On)
Field Codes (Off) <Bookmark Name> \* charformat\* ordinalNote: In place of <Bookmark Name>, type the name of the FORM field bookmark you noted in step 3.
' day of 'MMMM, yyyyIf 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.
12 day of August, 1994
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
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.
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.
Q160988 WORD 97: How To Create Ordinal (Legal) Dates In Form Fields
"Microsoft Word User's Guide," version 6.0, pages 309-310, 317-318, 326
Kbcategory: kbusage kbmacro kbhowto
Additional query words: 6.00a formtext winword word6 6.00c word95 word7
Keywords : kbdta kbfield word6 word7 word95
Issue type : kbhowto
Technology :
|
Last Reviewed: November 4, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |