using DateAdd function in a Word form field

L

lsnoble

I've bashed my head against this all day, and gee, my head hurts! I've
pulled out an awful lot of my hair over this problem. Hope someone can
help with this:

I've created a residential lease contract as a simple form where users
can input basic data involved in the lease agreement, such as Lessor's
name, Lessee's name, and so forth. In the terms of the lease, I want
users to be able to enter the start date of the lease (e.g., March 1,
2007), but I want the end date to be calculated automatically in the
next field so that the end date is one year from the start date (e.g.,
February 28, 2008). I've read what seems like volumes of material about
using the DateAdd function in VBA, which should allow me to run a macro
with this code OnExit from the start date field, but none of the code
I've tried works! GAAAAHH! I'm not at all familiar with using VBA, so I
don't understand how and where to type the code for the DateAdd
function.

The best work-around I've found is to create separate fields for the
years (i.e., a field for "March 1" and a field for "2007), then add a
formula to the field where I want to force the year to update by 1.
Easy, but my client doesn't seem satisfied with this. The client wants
the form to be as error-proof as possible, and doesn't even want users
to have to type in "February 28" (for example).

I would really appreciate some help with this, since I don't have much
hair left.

L.
 
L

lsnoble

Thank you for your quick reply!

However, I have gone over this document very carefully, and it
unfortunately doesn't contain the information that I need. Thanks so
much, anyway, for your input.

L.
 
M

macropod

Hi lsnoble,

In the document Graham referred you to, the field under the heading
'Calculate a day, date, month and year, using n (301) days delay' can be
used. It just takes a little lateral thinking.

The following is predicated on you setting up the Section of the document
with the date calculation as a protected form:
1. At the point in your document where you want to enter the start date of
the lease-
a) insert a formfield to gather that information;
b) modify the formfield's properties to require a date input in the
desired format;
c) give the formfield a bookmark name (eg 'StartDate'); and
d) set the formfield's properties to 'calculate on Exit'.
2. Insert the field under the heading 'Calculate a day, date, month and
year, using n days delay' at the point in your document where you want to
output the end date of the lease
3. Edit that field (Press Shift-F9 to expose the code) by-
a) changing the contents of the field coded as '{SET Delay 301}' to '{SET
Delay -1}';
b) inserting '+1' after {DATE \@ yyyy} (ie to give ({DATE \@ yyyy}+1');
and
c) changing all instances of 'DATE' to 'StartDate' (or whatever bookmark
name you chose for the formfield).

Subject to any regional date output format changes you might need to make
(see the 'Date input/output formats' in the 'Introductory Notes'), the field
will now be ready for use.

Cheers
 

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