Textbox display month and year with buttons

Wilse

Registered User.
Local time
Yesterday, 17:17
Joined
Mar 8, 2010
Messages
92
Hi guys,

I am very new to access and VB so I am sorry of this is a stupid question.

I am creating a database for my work and I would like the text box to display the current month and year. I would like to command buttons each side one to go back a month and the next one to go to the next month.

I would like this to be used to select the month so only the selected months records would be displayed.

Can anyone help me please?
 
Lookup the DateAdd() and Format() functions. Just what you need ;)

Welcome to AWF!
 
I have got

=Format$(DateAdd("m",0,Now()),"mmmm yy")

to display the current month and year in the textbox but I am unsure how to tie this with the command buttons to go back or forward months
 
Last edited:
That was very efficient of you looking both up and coming up with something :)

You need one or the other.

To display the current month you can use:
Format(Date(),"mmmm")
OR
MonthName(Date())

You write code like this on the ON CLICK event of the command button (look under EVENTS tab of the button):
Code:
Name_Of_Textbox = MonthName(date())
 
what about displaying the year as well
 
You can use the Format example I gave and just add yy or yyyy depending on what you want.
 
ah sorry to be a pain, I am just way out of my depth here
 
That's what the forum is for. We've all been there :)
 
I am getting no joy, my textbox is called monthtext so what code do I place on on the ON click event
 
Code:
monthtext = Format(Date(),"mmmm yy")

And what you need is the CODE BUILDER option when you click the elipsis "..."

Put it between the two lines of code that you see on the window that opens up.
 
where do i put the +1 or -1 to change the month on the code and do i put =Format(Date(),"mmmm yy") as the control source as the textbox or do I put it somewhere else
 
I have syntax error when I click the button
 
Ah it now displays april 10 but when I click the button it stays as April 10 and not May 10.

I have
Private Sub Command12_Click()
monthtext = Format(DateAdd("m", 1, Date), "mmmm yy")
End Sub
 
but I wanna use it to select different months not just this month, next month and last month. I wanna go back for example 1 year if i click the button 12 times
 
That wasn't what you expressed in your initial post.

Don't you think you should replace Date() with something?
 
You need to change it to:

Code:
monthtext = Format(DateAdd("m", 1, [B][COLOR=red]monthtext[/COLOR][/B]), "mmmm yy")
 
That wasn't what you expressed in your initial post.

Don't you think you should replace Date() with something?

Sorry, I gave away the answer :o:o:o:o
 

Users who are viewing this thread

Back
Top Bottom