Button to navigate/Filter records from month to month and year to

S

Silvio

I would like to add two buttons to my form that will be used to navigate
(filter) my records by month and years. In few words, if a click on the
"previous month" (<<) button the record from December 2008 will display, if I
click once again will display records from November 2008 and so on. Then if I
click on “next month†(>>) it will do the same think going forward (e.g.
November 2008 --> December 2008 --> January 2009 and so on up to the current
month and year). How can I accomplish this task?

Thanks!
 
D

Dale Fye

Silvio,

It would depend on how you have your form organized now. Is this a
continuous form, or single form with navigation buttons?

What is the SQL for the recordsource of the form? Do you have the forms
Filter property set to anything? Or do you want to actually make changes to
the SQL that is the forms RecordSource?

Do you have a lot of records in the recordset?

Are you operating over a LAN or is your data on your hard drive?

One way to do this would be to use the forms Filter and FilterOn properties,
and store a date relating to the current month in the forms Tag property.
Code to suport this might look like:

Private Sub cmd_Prev_Click()

Me.Tag = DateAdd("m", -1, CDate(Me.Tag))
Me.Filter = "Format([DateField],'yyyymm')=" _
& Chr$(34) & Format(Me.Tag, "yyyymm") & Chr$(34)

End Sub

Private Sub cmd_Next_Click()

Me.Tag = DateAdd("m", 1, CDate(Me.Tag))
Me.Filter = "Format([DateField],'yyyymm')=" _
& Chr$(34) & Format(Me.Tag, "yyyymm") & Chr$(34)

End Sub

Private Sub Form_Open(Cancel As Integer)

Me.Tag = DateSerial(Year(Date), Month(Date), 15)
Me.Filter = "Format([DateField],'yyyymm')=" _
& Chr$(34) & Format(Me.Tag, "yyyymm") & Chr$(34)
Me.FilterOn = True

End Sub
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 

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