Thanks Duane for your answer. It seems like I will be in for some work. I am
try to get the date selection to work. This is what I have and it breaks at
the last line for the report.
Private Sub txtRosterStart_AfterUpdate()
Dim strSql As Date
Dim stDocName As String
If IsNull(frmDates) Then
MsgBox "No date criteria is selected!", vbInformation
If Me.txtCriteria = "<" Then
strSql = "SELECT .... WHERE [DateOfClassStart]"
strSql = strSql & " <#" & Me.txtRosterStart & "#"
CurrentDb.QueryDefs("Query7").SQL = strSql
ElseIf Me.txtCriteria = ">" Then
strSql = "SELECT .... WHERE [DateOfClassStart]"
strSql = strSql & " >#" & Me.txtRosterStart & "#"
CurrentDb.QueryDefs("Query7").SQL = strSql
ElseIf Me.txtCriteria = "=" Then
strSql = "SELECT .... WHERE [DateOfClassStart]"
strSql = strSql & " =#" & Me.txtRosterStart & "#"
CurrentDb.QueryDefs("Query7").SQL = strSql
ElseIf Me.txtCriteria = ">=" Then
strSql = "SELECT .... WHERE [DateOfClassStart]"
strSql = strSql & " >=#" & Me.txtRosterStart & "#"
CurrentDb.QueryDefs("Query7").SQL = strSql
ElseIf Me.txtCriteria = "<=" Then
strSql = "SELECT .... WHERE [DateOfClassStart]"
strSql = strSql & " <=#" & Me.txtRosterStart & "#"
CurrentDb.QueryDefs("Query7").SQL = strSql
End If
End If
DoCmd.OpenReport "rptQuery7", acPreview, , strSql
End Sub
:
I generally create reports based on queries that have little or no criteria.
I use code to create a "where clause" that can be used in the
DoCmd.OpenReport method. For instance rather than have a criteria in a
report's record source like:
Between Forms!frmDates!txtStart and Forms!frmDates!txtEnd
I would use code like:
Dim strWhere as String
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport "rptMyReport", acPreview, , strWhere
I think this method provides a great deal of flexibility.
--
Duane Hookom
MS Access MVP
--
I have a variety of reports that need to be filtered I am not sure of the
approach to take. Should I create a different query for each type of
filter.
Then use those queries to develop the query for the report? How should I
do
this to make life easy for the programmer (me), the users, the database,
and
the future?
Should I create the code as a Public Function and then call it for each
individual report as needed?
Any advise would be appreciated. Thank you. Fay