DateAdd function

S

samiboy

Morning-
I've seen some posts that address this function, but no real solutions- just
redirects to other pages.

I have a form that uses a normal word text field (not an activeX control).
It is referenced by a bookmark named "deadline"

could someone tell me how to properly call a VBA function using DateAdd that
fills in another field with a date 14 days from now?

Has anyone else tried to do this? It seems simple, but when you get down
to it, all the links I've looked at are horrendous....
 
M

Martin Seelhofer

Hi Samiboy (nice name)
could someone tell me how to properly call a VBA function using DateAdd
that
fills in another field with a date 14 days from now?

1. Let's assume you have two formfields. Formfield 'MyDate' is the textbox
containing the user defined date. Formfield 'Deadline' is the textbox
that
will receive the calculated deadline date. Both formfields are properly
set up (correct date format chosen).

2. Write a macro, which does your calculation, e.g.:
Sub CalcDeadline()
Dim dat As Date
With ActiveDocument.FormFields
dat = .item("MyDate").Result
.item("Deadline").Result = dat + 14
End With
End Sub

You don't have to use DateDiff at all. However, if you do want to
use it, replace the code fragment [dat + 14] with the following:
DateAdd("d", 14, dat)

3. Edit Formfield MyDate's properties and choose the above macro
as the OnExit-macro.

4. Protect the form and try the whole thing...


Cheers,
Martin
 
S

sjane

Give this code a try:

Sub DatePlusFourteen ()

Dim strToday As String

Dim strTomorrow As String

strToday = "Today is " & Format$(Now, "mm/dd/yy")

strTomorrow = "Fourteen Days from Today is " & Format$(Now + 14, "mm/dd/yy")

Selection.InsertAfter strToday & vbCrLf & strTomorrow

End Sub

sjane
 
S

samiboy

Guys-
Thank you for both replies. Simple, easy to understand, and concise.
Feeling like a bit of an idiot- I just needed to see the DateAdd function in
action.

Thanks!
Sam
 

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