specific but changing date code

J

Jeff

I want to insert a field code into a form that would
display the following Sunday's date. For our church
secretary as she makes the bulletin each week. The date
that would show up as she edits the form would be the
following Sunday's date. Any ideas?? I'm stumped.
 
G

Graham Mayor

Calculations on date codes are extremely complex and best avoided - See the
relevant section on dates at
http://www.addbalance.com/word/wordwebresources.htm

A macro is a much simpler proposition and the following will insert next
Sunday's date. (You can change the mask on the last line to suit your date
formatting requirements).

Sub InsertSunday()
Today = (Now)
Do Until Sunday = "Sun"
Today = Today + 1
Sunday = Format(Today, "ddd")
Loop
Selection.InsertAfter Format(Today, "dddd, d MMMM yyyy")
End Sub

See http://www.gmayor.dsl.pipex.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.dsl.pipex.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
G

Graham Mayor

Macropod's document is certainly a 'tour de force' on the topic of date
fields and well worth investigating (to which end I have added the link to
my own web page), but it serves to emphasise the complexity of date
calculations using fields. The macro approach is certainly simpler, and will
not cause problems with (correctly setup) macro security if the macros are
stored in the document or global templates where they belong.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.dsl.pipex.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
D

Doug Robbins - Word MVP

Hi Jeff,

Here's a neater bit of code:

Selection.InsertBefore Format(DateAdd("d", 8 - Weekday(Date), Date), "d MMMM
yyyy")

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top