Report Date Picker
Submitted by Bruce Riggs CIS 76142,155
09/09/1995
For Access 2.0

RPTDATES.MDB contains two forms and two tables, used to allow users to quickly pick report dates. It was designed to avoid the problem of users typing dates incorrectly when establishing date criteria for reports.

You can import the two tables and forms into your own application, and make whatever changes may be needed. frmReportDates, which picks for one month, won't need to be changed. Form frmReportQtr, assumes the first quarter starts on Jan 1. Many organizations use a different fiscal year, so you will have to make changes accordingly. The changes must be made to the table tblQtr. The Form_Open event procedure of form frmReportQtr, shown below, uses the QtrID field in tblQtr to display the current date and name it according to it's quarter.

tblQtr:
QtrID		Quarter
1		1st Quarter
4		2nd Quarter
7		3rd Quarter
10		4th Quarter

QtrID is the number of the month, that is the first month of that quarter. By changing the values in tblQtr, field QtrID, you can change your first quarter to any month. If, for example, your fiscal year starts in July, change QtrID 1 to 7. Then change the other QtrIDs accordingly.
The changes could also be made in the code below, but it is simpler to just change the table.

To change the table, you must first delete the PrimaryKey. Make the changes, then re-establish the PrimaryKey.

Sub Form_Open (Cancel As Integer)
    Dim QtrToday As Integer
    QtrToday = DatePart("m", Now) 'The variable QtrToday is set as the number of the month.

    Select Case QtrToday
        Case 1 To 3
            [QtrPick].Value = 1 '[QtrPick] is the unbound listbox on the form.
        Case 4 To 6
            [QtrPick].Value = 4
        Case 7 To 9
            [QtrPick].Value = 7
        Case 10 To 12
            [QtrPick].Value = 10
    End Select

    [SystemDate] = Date
    [DateDisplay] = DatePart("yyyy", Date)
    [OriginalDate] = Date

End Sub

There are two hidden fields on the form, [SystemDate], and [OriginalDate]. When the form opens, [SystemDate] and [OriginalDate]are the same. If you change the year displayed, [SystemDate] changes, as does your actual computer date. When the form is closed, the computer system date is reset to [OriginalDate]. Actually changing the computer system date, allows for simpler code (I couldn't figure out any other way to do it).

The functions in [StartDate] and [EndDate], on both forms, use Access date functions which rely on your system date.

To use the forms for report date setting, make your reports reference the [StartDate] and [EndDate] fields on the form. Use the print button on the Date forms to first hide the form, then print the report or reports. The date form must stay open (hidden) for the report to see it. Have the report close the date form when it finishes printing.