Date + 1 Month

K

kevin123

Hi there, I'm pretty new so bear with me.

I have a word document ask a user what a certain date is. Let's call it
"DATE A".

This date is inserted into the first row of a table.

I need to add 1 Month to this date in the next row. 2 Months to this date in
the row below, etc.

I.E. Let's assume DATE A is January 01, 2007. I need the next date in the
table to be Febuary 01, 2007, then March 01, 2007 etc.

Any clue on how I would do this? I've looked everywhere, and every thing
seems to be a little over my head.

Much appreciated. :)
Kevin
 
K

Karl E. Peterson

kevin123 said:
Hi there, I'm pretty new so bear with me.

I have a word document ask a user what a certain date is. Let's call it
"DATE A".

This date is inserted into the first row of a table.

I need to add 1 Month to this date in the next row. 2 Months to this date in
the row below, etc.

I.E. Let's assume DATE A is January 01, 2007. I need the next date in the
table to be Febuary 01, 2007, then March 01, 2007 etc.

Any clue on how I would do this? I've looked everywhere, and every thing
seems to be a little over my head.

Well, the first step is always breaking the job down into its constituent
parts/tasks. For example, saying "add 1 month" is extremely vague. Do you mean you
want to add 28, 29, 30, or 31 days? Or, do you mean you want to arrive at the same
date next month? I sense the latter, which would be something like this:

NewDate = DateSerial(Year(OldDate), Month(OldDate) + 1), Day(OldDate))

This is a many-faceted job. Which part(s) are you having trouble with?
 
K

kevin123

Thank you for your reply, and you are right. It's the latter. I want to
arrive at the same date each month.

I am having trouble with doing the actual formula to calculate a given date
+ 1 Month

When the user first opens the document, I ask them this:
{ ASK effdate "Effective Date of Contract? DD/MM/YYYY"}{REF effdate}

Now, I know that's very basic, and vague, and most likely wrong- so if you
can suggest a better way of gathering "DATE A" from the user, please tell.

Thank you for replying, I look forward to any suggestions and solutions you
may have.
 
K

Karl E. Peterson

kevin123 said:
Thank you for your reply, and you are right. It's the latter. I want to
arrive at the same date each month.

I am having trouble with doing the actual formula to calculate a given date
+ 1 Month

When the user first opens the document, I ask them this:
{ ASK effdate "Effective Date of Contract? DD/MM/YYYY"}{REF effdate}

Now, I know that's very basic, and vague, and most likely wrong- so if you
can suggest a better way of gathering "DATE A" from the user, please tell.

Thank you for replying, I look forward to any suggestions and solutions you
may have.

Hmmmm, well, that's not VBA, I'm afraid. I know VB, which by extension means I know
VBA. But what you're asking about now (albeit in a VBA group) is something that
isn't within my domain. I already gave you the formula to use *withing VBA* to
calculate the "same date next month". I'm not at all sure how that may be applied
to this situation, though. Sorry...
 
J

Jean-Guy Marcil

kevin123 was telling us:
kevin123 nous racontait que :
^ well I can try to use the VBA example you gave...

This can be a little difficult if you have never done any VBA.

First of all, if you are dealing with user input, there will be error on
their part that will make the code unusable. So, you have to have some kind
of error trapping. In this case the easiest would be with a MessageBox that
whose content can be validated before allowing the user to go on.

Once this has been done, you would probably end up with a date in a string
format, i.e. the compiler does not know it is a date, it is just some digits
stringed together that do not mean anything to the compiler. See the two
code example below where in the first case the compiler knows it is dealing
with a date, but not in the second case.

Next, you have not specified how many rows in the table must be affected by
the "plus one month" count.

Finally, you have to realise that if a date that would cause an error is
used (i.e., there is no June 31st, so May 31st will produce July 1st) then
the next available date will be generated.

'_______________________________________
Sub DateFormat()

Dim NewDate As Date
Dim OldDate As Date

OldDate = Date

NewDate = DateSerial(Year(OldDate), Month(OldDate) + 1, Day(OldDate))

MsgBox NewDate

End Sub
'_______________________________________

'_______________________________________
Sub DateString()

Dim NewDate As Date
Dim OldDate As String
Dim arrDate() As String

OldDate = "01/29/2007"
arrDate = Split(OldDate, "/")

NewDate = DateSerial(arrDate(2), arrDate(0) + 1, arrDate(1))

MsgBox NewDate

End Sub
'_______________________________________

If you do not want any VBA, fields are possible, see
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
especially, the section labelled "Automatically Insert A Past Or Future
Date, Adjusted By +/- A Number Of Days, Weeks etc,"
But event that will be difficult if you start with user input, which can be
unreliable.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

macropod

Hi Kevin,

To see how to do this and just about everything else you might want to do with dates in Word, using fields as you've described
rather than vba, check out my Date Calc 'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
In particular, look at the item titled 'Automatically Insert A Past Or Future Date', which has various month-based examples. Using
the code under 'Calculate a day, date, month and year, using n months delay', for example, you'd make the 'Delay' variable in your
chosen field '1', add an ASK field to the code and replace the 'DATE' expressions with the name of the bookmark set by your ASK
field's bookmark.

Cheers
 
G

Graham Mayor

Ahhh! I see Macropod has already suggested this in another branch of the
thread. :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jean-Guy Marcil

Graham Mayor was telling us:
Graham Mayor nous racontait que :
Ahhh! I see Macropod has already suggested this in another branch of
the thread. :)

I suggested it before he did... so now we have three references to the same
page... No way the OP can miss it now!

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Graham Mayor

Don't count on it ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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