Navigate through month and year in access form?

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

In the formheader of an access form I like to create two buttons one for brevious and one for next button to navigate through Month and Year.

For example:
When I open the form I like to show me the current Month and Year in either a label or a textbox (not sure which would be better in this case)
If I click on the previous button I like to show Dezember 2016... and so on going back each click the same in the other direction going forward in the Month and year..

I am not sure how to go about it? Do need a table with Month and Year??
The reason behind this if I select a month I like on the form a listbox showing me only entries of that selectet month..

Cheers...

Silentwolf
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Create a label on your form called "lblDate" and two command buttons called "cmdNext" and "cmdPrevious".


Then add the following code to the form's module:


Code:
Private Sub Form_Load()
  Call UpdateLabel(Date)
End Sub


Private Sub cmdNext_Click()
  Call AddMonths(1)
End Sub


Private Sub cmdPrevious_Click()
  Call AddMonths(-1)
End Sub


Private Sub AddMonths(ByVal intIndex As Integer)
  Dim dtmTheDate As Date
  dtmTheDate = DateValue(Me.lblDate.Caption)
  dtmTheDate = DateAdd("m", intIndex, dtmTheDate)
  Call UpdateLabel(dtmTheDate)
End Sub


Private Sub UpdateLabel(ByVal dtmNewValue As Date)
  Me.lblDate.Caption = Format(dtmNewValue, "mmmm yyyy")
End Sub


You'll then need to configure your list box's RowSource to handle the changing date.
 
Upvote 0
Did you consider using the built in calendar control? If a textbox is bound and you move on to a new record, that calendar still works. If the textbox is not bound but the format is set to one of the date types, it still works. Having 2 would enable you to present your list results between two dates if that were useful.
 
Upvote 0
Hi ParamRay,

sorry for this late reply was not able to get on here for a while! Many thanks for this code I will try it!

cheers
 
Upvote 0

Forum statistics

Threads
1,221,700
Messages
6,161,371
Members
451,700
Latest member
Eccymarge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top