Run a calculation, then insert a month name

T

Thomas

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
 
K

Karl E. Peterson

Thomas said:
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

:)
 
T

Thomas

Karl:

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

Karl E. Peterson

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.
 
T

Thomas

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.
 
G

Graham Mayor

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

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Thomas

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?
 
G

Graham Mayor

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.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Thomas

Graham:

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

Graham Mayor

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" }" }


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


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


Thomas said:
Graham:

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

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