WD97: How To Create Ordinal (Legal) Dates In Form Fields

Last reviewed: March 11, 1998
Article ID: Q160988
The information in this article applies to:
  • Microsoft Word 97 for Windows

SUMMARY

This article provides a method you can use to automatically display dates in Arabic ordinal form (sometimes referred to as legal form) using Word form fields.

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

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

     
   http://www.microsoft.com/support/supportnet/refguide/default.asp

The following macro retrieves the valid date result typed into a form field, extracts the day from the date and determines the ordinal based upon that day. The macro finishes by returning the new Date formatting to the form field using the Visual Basic for Applications Format function.

   Sub GetOrdinalDates()
      Dim fDate As FormField
      ' If no documents are open or if no form fields
      ' exist in the active document, or for other
      ' errors, exit this routine.
      On Error GoTo errhandler
      ' Replace the word Date with the name of your
      ' form field with your formfield bookmark name.
      Set fDate = ActiveDocument.FormFields("Date")
      ' Is the result of the form field a valid date?
      If Not IsDate(fDate.Result) Then Exit Sub
      ' Determine date format.
      Select Case Day(fDate.Result)
         Case 1, 21, 31
            daysuffix$ = Day(fDate.Result) & "st"
         Case 2, 22
            daysuffix$ = Day(fDate.Result) & "nd"
         Case 3, 23
            daysuffix$ = Day(fDate.Result) & "rd"
         Case Else
            daysuffix$ = Day(fDate.Result) & "th"
      End Select
      
      ' Use ONE of the following formats.
      ' Remove the remark(apostrophe) from the
      ' command lines that produce the desired format.
      ' -----------------------------------------------
      
      ' - Format example: 24th day of February, 1998
   '   fDate.Result = daysuffix$ & " day of " _
   '      & Format$(fDate.Result, "mmmm, yyyy")

      ' - Format example: February 24th, 1998
   '   fDate.Result = Format$(fDate.Result, "mmmm") & " " & _
   '       daysuffix$ & Format$(fDate.Result, ", yyyy")

      ' - Format example: Tuesday the 24th, 1998
   '   fDate.Result = Format$(fDate.Result, "dddd") & " the " & _
   '      daysuffix$ & Format$(fDate.Result, ", yyyy")
   errhandler:
   End Sub

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q173707
   TITLE     : OFF97: How to Run Sample Code from Knowledge Base Articles

Create the Form

NOTE: There must be two form fields in the form for this example to work.

  1. On the View menu, point to Toolbars, and then click Forms.

  2. On the Forms toolbar, select "Text Form Field" and then click the Options button.

  3. From the Type list, choose Text.

  4. Under Field Settings, replace "Text1" with the word "Date" (excluding the quotation marks).

  5. In the Exit list box under "Run Macro On", select the "GetOrdinalDates" macro.

  6. Click OK.

  7. Repeat step 2 to insert a second form field.

  8. On the Tools menu, click Protect Document.

  9. Select the Forms option and then click OK. Word moves the insertion point to the first form field.

  10. In the form field you have designated to be the date, type the numeric date value. For example, type "12/10/97" (without the quotation marks).

  11. Press TAB to move to the next form field.

For information about how to do this in earlier versions of Word, please see the following article here in the Microsoft Knowledge Base:

   ARTICLE-ID: Q117267
   TITLE     : WD: How to Create Ordinal (Legal) Date Formatting in FORM
               Fields

REFERENCES

For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q163435
   TITLE     : VBA: Programming Resources for Visual Basic for 
               Applications


Additional query words: vb vba vbe
Keywords : kbdta kbdtacode kbwordvba word8 word97 kbprg
Version : 97
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 11, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.