Help? Get date from user and then add days to input? 
Author Message
 Help? Get date from user and then add days to input?

I want to create a Word macro that pops up a dialog box asking the
user to input a date (ie. a start date). Then I want to fill out the
document with values such as that date + x days (ie. deadlines that
are so many days from start date).

How can I do this?

Thanks for any help.



Fri, 02 Apr 2004 23:11:01 GMT  
 Help? Get date from user and then add days to input?
See <URL: http://www.addbalance.com/word/datefields2.htm> for ideas on
handling the date. If you go with use of fields (which will work for up to
28 days difference) they will work based either on the date the item is
printed or the date it is created. If you are using VBA you will need to use
an input box or a userform to get the date from your user and work from
there. You may want to look at the MVP website (link below) for information
on userforms, input boxes, and vba date handling.
--
Charles Kenyon

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

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.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.

Quote:

> I want to create a Word macro that pops up a dialog box asking the
> user to input a date (ie. a start date). Then I want to fill out the
> document with values such as that date + x days (ie. deadlines that
> are so many days from start date).

> How can I do this?

> Thanks for any help.



Fri, 02 Apr 2004 23:57:05 GMT  
 Help? Get date from user and then add days to input?

Here's what I have so far but it doesn't work. All it does is add a
number to the month.

Sub InsertFutureDates()
Dim strData As Date

strData = InputBox("Enter the renewal date (dd/mm/yyyy)", "d/mm/yyyy")
Selection.InsertBefore Format((strData + 2), "d/mm/yyyy")

End Sub

Any idea how to modify this so that it adds 2 days to the input date?

Thanks.

Quote:

>I want to create a Word macro that pops up a dialog box asking the
>user to input a date (ie. a start date). Then I want to fill out the
>document with values such as that date + x days (ie. deadlines that
>are so many days from start date).

>How can I do this?

>Thanks for any help.



Sat, 03 Apr 2004 00:33:36 GMT  
 Help? Get date from user and then add days to input?
Hi, Vector,

Your code works OK for me (recognizing that you've chose the date format
with days first and then month, the results I got added 2 to the first
number, which represents the days).

Another way to approach this, which gives more control over the amount of
added time, is to use the DateAdd statement, like this:

Sub InsertFutureDates()
Dim strData As Date, nDays As Integer

strData = InputBox("Enter the renewal date (dd/mm/yyyy)", "d/mm/yyyy")
nDays = Val(InputBox("Enter number of days to advance", "Add days", "2"))
strData = DateAdd(interval:="d", Number:=nDays, Date:=strData)
Selection.InsertBefore Format(strData, "d/mm/yyyy")

End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:

> Here's what I have so far but it doesn't work. All it does is add a
> number to the month.

> Sub InsertFutureDates()
> Dim strData As Date

> strData = InputBox("Enter the renewal date (dd/mm/yyyy)", "d/mm/yyyy")
> Selection.InsertBefore Format((strData + 2), "d/mm/yyyy")

> End Sub

> Any idea how to modify this so that it adds 2 days to the input date?

> Thanks.


> >I want to create a Word macro that pops up a dialog box asking the
> >user to input a date (ie. a start date). Then I want to fill out the
> >document with values such as that date + x days (ie. deadlines that
> >are so many days from start date).

> >How can I do this?

> >Thanks for any help.



Sat, 03 Apr 2004 02:03:38 GMT  
 Help? Get date from user and then add days to input?

Dim sDate As String
Dim mydate As Date
sDate = InputBox("Enter start date")
If Not IsDate(sDate) Then MsgBox "Not a valid date": Exit Sub
mydate = CDate(sDate)
Selection.TypeText mydate & vbCr
Selection.TypeText DateAdd("d", 7, mydate) & vbCr
Selection.TypeText DateAdd("d", 14, mydate) & vbCr

To change the format of the dates produced, use the Format function,
e.g.:

Selection.TypeText Format(DateAdd("d", 14, mydate), "MM-dd-yy") & vbCr

Hope this helps.


-- See the MVP FAQ at http://www.mvps.org/word ----------------------
------------- "Life is nothing if you're not obsessed." --John Waters
---------------------------------------------------------------------
Please reply only to the newsgroup.

Quote:

> I want to create a Word macro that pops up a dialog box asking the
> user to input a date (ie. a start date). Then I want to fill out the
> document with values such as that date + x days (ie. deadlines that
> are so many days from start date).

> How can I do this?

> Thanks for any help.



Sun, 04 Apr 2004 08:42:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Date help, date - 14 days

2. Getting Days of Dates

3. help getting a SQLOLE.group object so I can add users to it

4. Adding number of days to Date() function

5. Adding Working Days Only to a Date

6. Adding days/ months/ years to date record

7. Adding 5 BUSINESS DAYS to a date

8. How can I Add days to a date

9. adding/removie days from a date

10. Adding Working Days Only to a Date

11. add seconds/minutes/hours/days/months to a date-value

12. adding days to dates

 

 
Powered by phpBB® Forum Software