Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Run a calculation, then insert a month name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thomas - 08 Nov 2007 19:21 GMT
Hey All:

Have a strange one here, I am looking to calculate based on todays date.  
For example, If today's date is between 1st & 15th, display current month
name.  If today's date is between 16th & 31st, display next month name.

Do you know a way of doing this?  Please advise
Karl E. Peterson - 08 Nov 2007 19:48 GMT
> Have a strange one here, I am looking to calculate based on todays date.
> For example, If today's date is between 1st & 15th, display current month
> name.  If today's date is between 16th & 31st, display next month name.

What part are you having trouble with?  The determination seems simple enough...

  Public Function GetMonth() As String
     If Day(Now) > 15 Then
        GetMonth = Format$(DateSerial(Year(Now), Month(Now) + 1, 1), "mmmm")
     Else
        GetMonth = Format$(DateSerial(Year(Now), Month(Now), 1), "mmmm")
     End If
  End Function

Of course, you could get a bit tricker there, by modifying like this:

  Public Function GetMonth() As String
     GetMonth = Format$(DateSerial( _
        Year(Now), Month(Now) + Abs(Day(Now) > 15), 1), "mmmm")
  End Function

:-)
Signature

.NET: It's About Trust!
http://vfred.mvps.org

Thomas - 08 Nov 2007 21:14 GMT
Karl:

How do I implement this into a word document? (Forgive me, I am not a
programmer, but I am dabling)

> > Have a strange one here, I am looking to calculate based on todays date.
> > For example, If today's date is between 1st & 15th, display current month
[quoted text clipped - 18 lines]
>
> :-)
Karl E. Peterson - 08 Nov 2007 21:32 GMT
Your turn...  Forgive me, for I am a programmer, and not much of a Word user...

Best I can offer is, "it depends."  I imagine if you can articulate the purpose,
someone here can suggest a good way.  For example, should it be injected immediately
when a new document is created, when the user punches a button, every other
paragraph in odd-numbered months?  Really need to define the trigger here.
Signature

.NET: It's About Trust!
http://vfred.mvps.org

> Karl:
>
[quoted text clipped - 26 lines]
>> ..NET: It's About Trust!
>>  http://vfred.mvps.org
Thomas - 09 Nov 2007 16:12 GMT
Karl:

Okay, here is the senario.  I am sending a letter out to clients.  Letters
are generated with a mail merge (one at a time) from another application.  
The letter is to confirm a client that signed up for a program and states
they will be billed on a specific date each month.  I need Word to calculate
if the client should be billed on the 10th or 20th of the month depending on
what today's date and month are.  

I don't want to bill them starting on Nov 10th if today is Nov 11th.  If
today is Nov 21st, I need to say the first bill will be Dec 10th.  I am sure
this is a tough one, is something like this possible?  Please advise.

> Your turn...  Forgive me, for I am a programmer, and not much of a Word user...
>
[quoted text clipped - 32 lines]
> >> ..NET: It's About Trust!
> >>  http://vfred.mvps.org
Graham Mayor - 10 Nov 2007 08:25 GMT
The following should work (without vba) using fields in the merge document

{ IF{ Text1 \@ dd } > 10  "{ IF{ Text1 \@ dd } > 20 "Billing Date { ={ Date
\@ "MM" } +1 }/10/{ Date \@ "yyyy"}" "Billing Date { Date \@ "MM" }/20/{
Date \@ "yyyy"}" }" "Billing Date { Date \@ "MM" }/10/{ Date \@ "yyyy"}" }

provided you are happy with date formats such as 10/11/2007 It gets a whole
lot more complicated otherwise - see Macropod's treatise on date
calculations at http://www.gmayor.com/downloads.htm#Third_party

The above field checks to see whether the current date is the 10th or the
20th of the month and sets the billing date to the 10th or 20th of the same
month or the 10th of the following month as appropriate

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Karl:
>
[quoted text clipped - 54 lines]
>>>> ..NET: It's About Trust!
>>>>  http://vfred.mvps.org
Thomas - 12 Nov 2007 13:28 GMT
Graham:

I recreated the string below (using Ctl+F9) but I do not have it working
yet.  I replaced the word "Date" with "Insert, Date & Time, Date Format" from
the menu bar.  Please let me know if this is correct.  Also, what do I put in
place of "Text1" field?

> The following should work (without vba) using fields in the merge document
>
[quoted text clipped - 68 lines]
> >>>> ..NET: It's About Trust!
> >>>>  http://vfred.mvps.org
Graham Mayor - 12 Nov 2007 16:30 GMT
Oops! Sorry - I was using a form field to create sample dates while testing
and forgot to restore the Date field in place of Text1, before posting :(
Change Text1 to Date and it should work :(
It will need some additional trapping to ensure that January isn't month 13
also, but I'll get back to that.
Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Graham:
>
[quoted text clipped - 87 lines]
>>>>>> ..NET: It's About Trust!
>>>>>>  http://vfred.mvps.org
Thomas - 12 Nov 2007 18:27 GMT
Graham:

Got it to work, Works Great!  Thank you so much.  Wow, this is Great!  Thank
You

> Oops! Sorry - I was using a form field to create sample dates while testing
> and forgot to restore the Date field in place of Text1, before posting :(
[quoted text clipped - 92 lines]
> >>>>>> ..NET: It's About Trust!
> >>>>>>  http://vfred.mvps.org
Graham Mayor - 13 Nov 2007 06:05 GMT
As promised, the extra trapping for year end dates

{ SET  Month "{ ={ Date \@ "MM" } + 1 }" }{ IF { Month} = 13 { SET Month
"01" } }{ IF{ Date \@  "dd"} > 10 "{ IF{ Date \@ "dd" } > 20 "Billing Date
{ ={ REF Month}}/10/{ Date \@ "yyyy" }" "Billing Date { Date \@
"MM" }/20/{ Date \@ "yyyy" }" }" "Billing Date { Date \@ "MM" }/10/{ Date \@
"yyyy" }" }

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Graham:
>
[quoted text clipped - 100 lines]
>> >>>>>> ..NET: It's About Trust!
>> >>>>>>  http://vfred.mvps.org
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.