Results 1 to 2 of 2
2010-04-01, 08:46 #1
- Join Date
- Apr 2010
- Thanked 0 Times in 0 Posts
First time here - loving the breadth and depth of knowledge on display.
I am hoping that someone may offer some assistance to a relative novice at this kind of thing - I have read Macropod's brilliant date/time document, and it has answered a lot of my questions but......
I am trying to create a Text Form Field in a Word 2007 Document that will accept a user input date (which won't get subsequently updated - but doesn't need to be locked) and I would like the date to be formatted including the ordinal for the day -
eg - 27th July 2010
I can get to the stage where the input is displayed as '27 July 2010' - where I am pulling my hair out is getting the 'th' dropped in there.
In the Text Form Field Options box I have tried appending the \* Ordinal switch after the d - eg d \* Ordinal MMMM YYYY but this doesn't work - I have tried a number of different alternatives, either with or without the curly brackets but nothing seems to work.
I really don't want to resort to VB and Macros - I can't help thinking there is a simple solution which I am somehow missing.
Thanks, in advance, for any suggestions,
2010-04-02, 23:26 #2
- Join Date
- May 2002
- Canberra, Australian Capital Territory, Australia
- Thanked 387 Times in 318 Posts
With your text formfield, you could mandate a simple 8-digit entry, in the form of DDMMYYYY, then use the following 'MakeOrdinalDate' macro as the formfield's 'on exit' macro:
Sub MakeOrdinalDate() With ActiveDocument.FormFields(Selection.Range.Bookmarks(1).Name) If Len(.Result) = 8 Then _ If IsDate(Left(.Result, 2) & "/" & Mid(.Result, 3, 2) & "/" & Right(.Result, 4)) Then _ .Result = OrdinalNumber(Left(.Result, 2)) & " " & Format(CDate(Left(.Result, 2) & "/" & Mid(.Result, 3, 2) & "/" & Right(.Result, 4)), "MMMM YYYY") End With End Sub Function OrdinalNumber(ByVal Num As Long) As String Dim N As Long N = Num Mod 100 If ((Abs(N) > 10) And (Abs(N) < 14)) Or ((Abs(N) Mod 10) > 3) Or ((Abs(N) Mod 10) = 0) Then OrdinalNumber = Format(Num, "0") & Format(Abs(N), "t\h") Else OrdinalNumber = Format(Num, "0") & Format(Abs(N) Mod 10 - 2, "r\d;\st;\n\d") End If End FunctionCheers,
[MS MVP - Word]