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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add date + 9 in word 2000 mail merge 1

Status
Not open for further replies.

stubnski

MIS
Nov 17, 2005
403
US
Hi VB experts!

I have a mail merge document in word 2000 with a merge field named effective_date. I need to insert a date 9 days in advance of the effective date (effective_date + 9).

Ex. effective_date = 5-1-06
date to be inserted = 5-10-06
NEXT DAY -
effective_date = 5-2-06
date to be inserted = 5-11-06...

The effective_date can be anywhere from 1 to 3 days older then the current date.

I need to insert this date twice in the mail merge document. The data source is a .txt file and is made daily.

I'm trying to find a way to keep things simple for the people who will be running the merge because they are computer illiterate.

Thanks in advance!

Stubnski
 
Have a look at the DateAdd function:
DateAdd Function


Returns a Variant (Date) containing a date to which a specified time interval has been added.

Syntax

DateAdd(interval, number, date)

The DateAdd function syntax has these named arguments:

Part Description
interval Required. String expression that is the interval of time you want to add.
number Required. Numeric expression that is the number of intervals you want to add. It can be positive (to get dates in the future) or negative (to get dates in the past).
date Required. Variant (Date) or literal representing date to which the interval is added.



Settings

The interval argument has these settings:

Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second



Remarks

You can use the DateAdd function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now.

To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").

The DateAdd function won't return an invalid date. The following example adds one month to January 31:

DateAdd("m", 1, "31-Jan-95")

In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.

If the calculated date would precede the year 100 (that is, you subtract more years than are in date), an error occurs.

If number isn't a Long value, it is rounded to the nearest whole number before being evaluated.

Note The format of the return value for DateAdd is determined by Control Panel settings, not by the format that is passed in date argument.

Note For date, if the Calendar property setting is Gregorian, the supplied date must be Gregorian. If the calendar is Hijri, the supplied date must be Hijri. If month values are names, the name must be consistent with the current Calendar property setting. To minimize the possibility of month names conflicting with the current Calendar property setting, enter numeric month values (Short Date format).

_________________
Bob Rashkin
 
Thanks Bong for the quick reply,

I'm new to VB so this is probably a simple thing to do, but how do you connect the merge field into the DateAdd function? Something along the lines of declaring a variable as Date, and then saying the variable = the merge field? Everything I've tried doesn't work.

This is what I have so far -

Private Sub Document_Open()
ActiveDocument.Bookmarks("DATE1").Range.Text = _
Format(Now + 9, "date")
ActiveDocument.Bookmarks("DATE2").Range.Text = _
Format(Now + 9, "mmm d yyyy")
End Sub

I have it adding 9 days to the current date because I can't figure out how to connect it to the merge field. Would it have to be a button to push instead of the document_open event?

Sorry for the headache

Thanks again!

Stubnski
 
Hi Stubnski,

Check out my Word Date calculation 'tutorial', at:
There you'll find a Word field pre-coded for insertion into your mailmerge document, under the heading 'Date Calculations In A Mailmerge', plus much more than you thought you'd ever need to know about date/time calculations in Word fields. All you'll need to do is to change the 'Delay' value and, depending on your regional settings and display preferences, the date format.

Cheers

[MS MVP - Word]
 
Thanks Macropod. I wasn't able to get the link to work, but I'll keep researching.



Stubnski
 
Thanks Macropod! This is going to help me out quite a bit. Thanks again.



Stubnski

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top