Month Changer

cath_hopes

Registered User.
Local time
Today, 16:32
Joined
Oct 17, 2007
Messages
52
Hi there,

I'm looking for some code to get a value of format 'Month YYYY' for this month, this month +1, +2 and this month -1 etc., then put it into a caption, but will be using it for other things too.
I've tried the following:

Dim Month1ago As Date
Dim Month2ago As Date
...

Month1ago = Month(Date) - 1
Me.Command13.Caption = Format$(Month1ago, "mmmm yyyy", 0, 0)

This returns Me.Command13.Caption with January 1900. So the format is wrong and Month(Date) - 1 seems to be removing a day rather than a month. There must be a simple answer to this. Can someone point me in the right direction?
Many thanks in advance!
Catherine
 
Use the dateadd function to "move" the date
Then format it like you are allready doing...
 
Your post is somewhat confusing, as you speak of "this month +1, +2 and this month -1" but then you have variable names like Month1ago and Month2ago which sound like you want this month -1, -2, but I'll give you some examples and the months they yield from today:

Code:
Month1Ago =  Format(dateadd("m",-1,Date),"mmmm yyyy ") 'March 2008 
Month2Ago =  Format(dateadd("m",-2,Date),"mmmm yyyy ") 'February 2008
CurrentMonth = Format(Date,"mmmm yyyy") 'April 2008
Month1Next = Format(dateadd("m",1,Date),"mmmm yyyy ") 'May 2008
Month2Next = Format(dateadd("m",2,Date),"mmmm yyyy ") 'June 2008
 
Thanks Mailman & Missinglinq - that's exactly what I was looking for and my code now works great!
Catherine
:-)
 

Users who are viewing this thread

Back
Top Bottom