Calculating a future date in Word 2000

B

BDeen

I've been trying to build a macro to take an existing date
that a user enters into a form field and then have a
future date calculated and inserted into a new form field
in long date format (January 15, 2004). So far, all I've
been able to do is convert the date to a serial number and
then enter the data as a short date (1/15/04).

Any suggestions?
 
S

Steve Yandl

You probably need to use the format function.

The sub below would enter the current date in the format you're wanting:

Sub myDate()
Dim myDate As Date
myDate = Now
Selection.TypeText (Format$(myDate, "mmmm d, yyyy"))
End Sub

Steve
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi BDeen

You need to use the DateAdd function to get the future date

If the user is entering the data into a formfield with the bookmark name
Date1 and you want a date, say 14 days later, to be displayed in a formfield
with the bookmark name of Date2, use the following code in a macro run on
exit from the Date1 formfield

ActiveDocument.FormFields("Date2").Result = Format(DateAdd("d", 14,
ActiveDocument.FormFields("Date1").Result), "MMMM d, 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
 
M

Martin Seelhofer

Hello there

Why not using the built-in formatting possibilities for Word-FormFields?
In design-mode (not protected for forms), double-click the FormField
and apply your settings. This way, you can fill in the value (.Result-
property of the FormField-object) without formatting it in VBA, it's
enough to assign the DateValue to it...


Cheers,
Martin
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Martin,

He was also wanting to calculate a future date. That's why you need to use
vba.

--
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
 
C

Charles Kenyon

For date calculations you _can_ use a complex field. See
<URL: http://www.chriswoodman.co.uk/Delayed Dates.htm> and
<URL: http://www.wopr.com/w3tfiles/10-249902-DateCalc.zip>


--

Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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