form for dynamic report...need help with a date feature

J

Jeffshex

I posted this on the fromscoding board, but thought i'd put it here too....
I have code that works already, with the exception of a date range. In the
database there is a field named BarDate that I want to run a query on. My
current form has code where if a field is blank on the form when you hit the
Apply Filter button, it uses the * to grab all of the info. I need help
implemeting the date part, which i cannot figure out. I'd like to have it
where if the leave the StartDate and
EndDate blank it shows everything, otherwise if those fields are filled in,
I'd like the query to insert the Between & And clause.
Any Ideas???
Here is the current code that works perfect...minus the date part :)

Private Sub cmdApplyFilter_Click()
' Declare variables for query string
Dim strServer As String
Dim strAdmin As String
Dim strPriority As String
Dim strRequestType As String
Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim strRequestName As String
Dim strFilter As String

' These IF statements tell the query to show all records if the selection is
left blank.
If IsNull(Me.cboServerName.Value) Then
strServer = "Like '*'"
Else
strServer = "='" & Me.cboServerName.Value & "'"
End If
If IsNull(Me.cboSysAdminName.Value) Then
strAdmin = "Like '*'"
Else
strAdmin = "='" & Me.cboSysAdminName.Value & "'"
End If
If IsNull(Me.cboPriority.Value) Then
strPriority = "Like '*'"
Else
strPriority = "='" & Me.cboPriority.Value & "'"
End If
If IsNull(Me.cboRequestType.Value) Then
strRequestType = "Like '*'"
Else
strRequestType = "='" & Me.cboRequestType.Value & "'"
End If
If IsNull(Me.cboRequestName.Value) Then
strRequestName = "Like '*'"
Else
strRequestName = "='" & Me.cboRequestName.Value & "'"
End If

strFilter = "[ServerName] " & strServer & " AND [RequestName] " &
strRequestName & " And [RequestType] " & strRequestType & " AND
[SysAdminName] " & strAdmin & " AND [Priority] " & strPriority & " "

With Reports![rptBAR]
.Filter = strFilter
.FilterOn = True
End With

End Sub
 
A

Allen Browne

Take a look at this example:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

The 2nd method in the example shows how to build the WHERE clause for the
dates. It works like this:
- StartDate only: returns all dates from that date forward;
- EndDate only: returns all dates up to the end date;
- both dates: returns records between the 2 dates;
- both blank: returns all records.
 

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