Your query is a simple Count query. The Where clause, obviously, is going to control what data is included.
I would create a form from which the users can select the criteria they want. For example, the user can select the book type(s) they want included in the count (simple multi-select list box). And a date range for the borrowed and a date range for the submitted. Depending on how you want it to work you could default the end date of the borrowed books to end of the current week (i.e. Saturday) and the number of weeks to 4. The begin date for the borrowed books would be a hidden field that you would compute based on the number of weeks selected.
Your form would look something like this:
Borrowed Books (End Date): 2/7/2009 Number of weeks: 4
Hidden Begin Date (Begin Date): 1/17/2009
Book Types (List Box): Type 1
Type 2
Type 3
...
Now, assume the end date is named txtDate_EndR and the Begin date is txtDate_BeginR and the Number of Weeks field is named txtNumWks. The Onload event of your form would look like this:
Code:
Private Sub Form_Load()
txtDate_EndR = DateAdd("d", Weekday(Date) + (7 - Weekday(Date)), Date)
txtNumWks = 4
Call txtNumWks_AfterUpdate
End Sub
The AfterUpdate event of the number of weeks field would look like this:
Code:
Private Sub txtNumWks_AfterUpdate()
txtDate_BeginR = DateAdd("ww", -txtNumWks, txtDate_EndR)
End Sub
This FAQ faq181-5497 contains a routine that will build the Where clause for you without the word Where. Simply copy the code from the FAQ and paste it in a new module. Set the Tag property of txtDate_BeginR to
Where=YourTable.BorrowedDate,date. To see how it works, add a button on your form and on the onclick event add the following code.
Code:
Private Sub Command6_Click()
MsgBox BuildWhere(Me)
End Sub
The msgbox will display the Where clause based on the begin and end date range. For example, with the data entered above, the msgbox should display
(YourTable.BorrwedDate Between #1/17/2009# and #2/7/2009#) Note, however, that the begin date is controlled by the number of weeks entered. Also note that the BuildWhere function will not include items that are invisible. Therefore, you cannot set the Visible property of the txtDate_BeginR to No, rather, you will need to set the background and foreground colors the same basically making it invisble.
To open your report from the form, use this command:
DoCmd.OpenReport "ReportName,acViewPreview,,BuildWhere(Me)
The FAQ explains how to use it. The main thing is setting up the Tag properties correctly
To get a feel for how what I've explained above works, create a new form and add 3 text boxes and a command button. The text boxes are named txtDate_BeginR, txtDate_EndR, and txtNumWks. The command button is named Command6. Add the OnLoad event code I've shown above, the AfterUpdate code from above and the Onclick code. Set the Tag property of the field txtDate_BeginR to what I've stated above. Now open the form and click the command button.