Hi =?Utf-8?B?TWFyaWFubmU=?=,
I'm working on a Word form and cannot get my text form field to calculate. I
know how to use the datediff function but I don't know which language to use in my
macro. I have a text field named "Date of Birth" and a text form field named "Date
of Note". I want the "Day of Life" form field to give me the difference between
the date of birth and the date of note but I don't know how. I also want a text
form field named "Day of Note" to automatically insert the "day" of the week
depending on the date of the note which is not always today.In the form fields' OPTIONS for these two dates you'd want to select the macro
that does the calculation from the "On Exit" list.
Word macros use VBA language, and DateDiff would be the same here as in other
Office apps or VB. You'd want to put the macro in a project, either that of the
template you use to create multiple form documents, or that of a single form
document you'll be re-using.
To get the information from the form fields for the calculation, you'd do
something like this:
Sub CalcDateDiff()
Dim doc As Word.Document, dt1 As Date, dt2 As Date
Set doc = ActiveDocument
If IsDate(doc.FormFields("Text1").Result) Then
dt1 = CDate(doc.FormFields("Text1").Result)
Else
MsgBox ("Enter a valid date in the first box")
End If
If IsDate(doc.FormFields("Text2").Result) Then
dt2 = CDate(doc.FormFields("Text2").Result)
Else
MsgBox ("Enter a valid date in the second box")
End If
doc.FormFields("Text3").Result = _
DateDiff("d", dt2, dt1)
End Sub
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word
This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail
![Smile :-) :-)](/styles/default/custom/smilies/smile.gif)