Just add 2 textboxes or comboboxes to the form linked to a date field in your data, and add the following code to the click event of the button which runs the report.
Just modify the code to fit your database fields. B-)
Private Sub ReportCmd_Click()
Dim RptName As String
Dim LinkFilter As String
Dim NumEntries As Integer
If (Me!BegDate > Me!EndDate) And (Not (IsNull(Me!EndDate))) Then
MsgBox "Error: Beginning date cannot be later than Ending date!", vbCritical
Me!BegDate.SetFocus
Exit Sub
End If
LinkFilter = ""
If Not (IsNull(Me!BegDate)) Then
If LinkFilter = "" Then
LinkFilter = "[Date] >= #" & Me!BegDate & "#"
Else
LinkFilter = LinkFilter & "And [Date] >= #" & Me!BegDate & "#"
End If
End If
If Not (IsNull(Me!EndDate)) Then
If LinkFilter = "" Then
LinkFilter = "[Date] <= #" & Me!EndDate & "#"
Else
LinkFilter = LinkFilter & "And [Date] <= #" & Me!EndDate & "#"
End If
End If
NumEntries = DCount("*", "table1", LinkFilter)
If NumEntries < 1 Then
MsgBox "There are no records which match the specified criteria.", vbInformation
Else
RptName = Me!ReportName
DoCmd.OpenReport RptName, acViewPreview, , LinkFilter
DoCmd.Close acForm, "ReportForm"
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.