Setting Dates in Word - first and last day of previous month

  • Thread starter Thread starter Barb Reinhardt
  • Start date Start date
B

Barb Reinhardt

Can someone direct me to some code to calculate the first and last day of
the previous month to be used in an Invoice?

Thanks in advance,
Barb Reinhardt
 
Hi Barb,

For a field-code solution, download the Word document at:
www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
(url all one line)
That document contains a tutorial for doing a wide range of date/time
calculations in Word, including some of the kind you're after.

If you need it, there are macro-based solutions also that I'm sure one of
the other contributors here could post.

Cheers
 
I believe I looked at that yesterday and had limited success. I can't seem
to open it today. Are there any tutorials for field codes and how to do
calculations, etc. with them? I haven't been able to find any.

Thanks for your assistance.
 
Let me ask a couple of more specific questions. I want to create several
date fields. They need to work for the following two circumstances.

1) If the CREATE DATE is any day in January 2005, how do I create the
following:
1st field: First date of previous month in format 12/1/2004
2nd field: Last date of previous month in format 12/31/2004
3rd field: Last date of prevous month in format December 31, 2004
4th field: Year portion of previous month in format 2004.
2) If the CREATE DATE is December 2004, how do I create:
1st field: First date of previous month in format 11/1/2004
2nd field: Last date of previous month in format 11/31/2004
3rd field: Last date of prevous month in format November 30, 2004
4th field: Year portion of previous month in format 2004.
 
I have the following as field codes

{ =IF( { CREATEDATE \@ "MM" } = 01 { CREATEDATE \@ "yyyy" } { = { CREATEDATE \@ "yyyy" }+1 \# "0000"} ) }



Everything in RED is working, but I can't get the IF statement to work. What am I doing wrong?
 
IF does not use parentheses in Word

{ =IF { CREATEDATE \@ "MM" } = 01 { CREATEDATE \@ "yyyy" } { = { CREATEDATE
\@ "yyyy" }+1 \# "0000"} }

For additional samples of IF statements in dates look at
http://addbalance.com/word/datefields2.htm.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: 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.

I have the following as field codes

{ =IF( { CREATEDATE \@ "MM" } = 01 { CREATEDATE \@ "yyyy" } { = { CREATEDATE
\@ "yyyy" }+1 \# "0000"} ) }



Everything in RED is working, but I can't get the IF statement to work.
What am I doing wrong?
 
I think you are trying to do the following:

{ IF { CREATEDATE \@ "MM" } = "01" "{ CREATEDATE \@ "yyyy" }" "{ =({
CREATEDATE \@ "yyyy" }+1) \# "0000" }"}

ie for January you want this year, for other months next year

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

My web site www.gmayor.com

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




I have the following as field codes

{ =IF( { CREATEDATE \@ "MM" } = 01 { CREATEDATE \@ "yyyy" } { = { CREATEDATE
\@ "yyyy" }+1 \# "0000"} ) }

Everything in RED is working, but I can't get the IF statement to work.
What am I doing wrong?
 
I have resolved some of the field codes and I get this:

{ =IF 12 = "01" "2004" "2005"}



But when I try to update the field, I get this:



!Syntax Error, 12
 
If in doubt, add quotation marks. Try
{ =IF "12" = "01" "2004" "2005"}

I am assuming that the 12 is generated by some other field. I haven't been
following the entire thread.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: 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.
 
It works fine here - are you setting all the field boundaries {} using
CTRL+F9 or are you simply typing them :(

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
The = sign is not required in front of the IF

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
I had to add commas to get it to work. I reviewed some of the examples
from a link posted by macropod and went from there. Thanks for your help
on this one.
 

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

Back
Top