Here is a sample of how I set up a database to display a report based on a range of dates (start date then end date). I created a form with unbound text boxes with a button marked submit then added the following code
Code:
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Me.Caption = Forms![Report Date Range].OpenArgs
End Sub
Private Sub Submit_Click()
If IsNull([Beginning Order Date]) Or IsNull([Ending Order Date]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "Beginning Order Date"
Else
If [Beginning Order Date] > [Ending Order Date] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "Beginning Order Date"
Else
Me.Visible = False
End If
End If
End Sub
Then in the report make sure that the fields match the criteria your entering in the form that you created. Once you've created the report add the following code to the report.
Code:
Option Explicit
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub
Private Sub Report_Close()
DoCmd.Close acForm, "Report Date Range"
End Sub
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "Report Date Range", , , , , acDialog, "Range Logs"
End Sub
Now I had 3 different reports that pulled information from 3 different tables but had a date range associated with them. I was able to use the same code on all three reports using the same form I created to input the criteria.
The code was created with date range in mind but I’m sure you can adapt it so that you can enter in any kind of data to pull specific information for a report.
Regards, Viper