Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fields codes in Microsoft Word

Status
Not open for further replies.

NIA2

Technical User
Aug 30, 2006
137
AU
Hi everyone,

I've used a field code to dynamically update a date in a document, but I've broken it up so that the day is one field and the month and year is another field, like this ("22" is one field, "April 2008" is the other):

22nd day of April, 2008

The problem is that the "nd" after 22 will need to change depending on the day of the month, ie. there would have to be "st" after 21 or "rd" after 23 etc.

Does someone know how I can get this part of the date to update/change according to the day, dynamically? Would I need VBA to do this or can it be done with Word's fields?

Thanks for any help offered.
 




Hi,

Check out faq707-6742.


Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
Thanks for the reply,

I'm having a bit of a problem figuring out how to use the function. I placed the following in a separate module:

Public Function pfun_OrdinalDate(dte_toformat As Date) As String

Select Case Day(dte_toformat)
Case 1, 21, 31
daysuffix$ = Day(dte_toformat) & "st "
Case 2, 22
daysuffix$ = Day(dte_toformat) & "nd "
Case 3, 23
daysuffix$ = Day(dte_toformat) & "rd "
Case Else
daysuffix$ = Day(dte_toformat) & "th "
End Select

pfun_OrdinalDate = daysuffix$ & Format$(dte_toformat, "mmmm") & Format$(dte_toformat, " yyyy")


End Function


Then pasted the following in the document:

?pfun_OrdinalDate(date())


Nothing happened - I'm sure I'm calling the function incorrectly and not sure how I can use the code to get the required format:

dated 22th day of April, 2008

Can you help further?
 
Hi gwh2,

To see how to do this, and much more besides, using field coding in Word, check out my 'tutorial' at:
in particular see the topic titled 'Insert A Date With Text Using A Formula Field'. There you'll see how to get the ordianls with and without superscripting.

Cheers

[MS MVP - Word]
 
Thanks so much - this is perfect!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top