Hi all,
I am building a report in Access 2003 that consists of several subreports that summarize data in a View I've created in SQL Server 2005 (note I am aware that some compatibility issues exist).
I need to filter the entire report based on input from a popup form that allows the user to specify a start date, end date, and / or Hospital. Any of these left blank are ignored.
I am pretty sure this is working properly for the main report, but am having trouble passing the filter expression to the subreports. Currently I am trying to set the Filter and FilterOn properties of a subreport from the onClick event handler of the view button on the popup form, before opening the main form:
So the filter expression is like this (without dates) "1=1 AND Hospital = 'Training Hospital 2'" or (with dates specified) "1=1 AND Hospital = 'Training Hospital 2' And Death_Date>= Convert(smalldatetime, '10/19/2008') And Death_Date<=Convert(smalldatetime, '11/20/2009')" or (with nothing specified) "1=1"
With any of these expressions, when I click the form's view button the main report opens and I get two identical error messages that read, "one or more operators in the filter expression is invalid, for a list of valid operators please refer to the help file".
OR sometimes I get a "Runtime error 2021: one or more operators in the filter expression is invalid" break during execution of the form button's event handler at the line where I set FilterOn=True.
Which error appears seems to vary with the following in a cryptic way that I can't seem to understand:
a)whether I have either report open in design view when I click the form button.
b)what filter expression / FilterOn status is hard-coded on the subreport.
Neither report has any associated VBA code.
Can anyone shed any light on this for me? Any suggestions much appreciated.
Thanks
Rick
I am building a report in Access 2003 that consists of several subreports that summarize data in a View I've created in SQL Server 2005 (note I am aware that some compatibility issues exist).
I need to filter the entire report based on input from a popup form that allows the user to specify a start date, end date, and / or Hospital. Any of these left blank are ignored.
I am pretty sure this is working properly for the main report, but am having trouble passing the filter expression to the subreports. Currently I am trying to set the Filter and FilterOn properties of a subreport from the onClick event handler of the view button on the popup form, before opening the main form:
Code:
Private Sub view_Click()
Dim strWhere As String
Dim strReportName As String
strReportName = "Donor Summary"
strWhere = "1=1"
Const strcJetDate = "mm\/dd\/yyyy"
If Not IsNull(Me.cboHospital) Then
'EmpID is numeric
strWhere = strWhere & " AND Hospital = '" & Me.cboHospital & "'"
End If
If Not IsNull(Me.txtStartDate) Then
'DateField is a date
strWhere = strWhere & " And Death_Date>= Convert(smalldatetime, '" & Me.txtStartDate & "')"
End If
If Not IsNull(Me.txtEndDate) Then
'DateField is a date
strWhere = strWhere & " And Death_Date<=Convert(smalldatetime, '" & Me.txtEndDate & "')"
End If
[Report_Donor_Summary_Hospital].FilterOn = True
[Report_Donor_Summary_Hospital].Filter = strWhere
DoCmd.OpenReport strReportName, acPreview, , strWhere
End Sub
So the filter expression is like this (without dates) "1=1 AND Hospital = 'Training Hospital 2'" or (with dates specified) "1=1 AND Hospital = 'Training Hospital 2' And Death_Date>= Convert(smalldatetime, '10/19/2008') And Death_Date<=Convert(smalldatetime, '11/20/2009')" or (with nothing specified) "1=1"
With any of these expressions, when I click the form's view button the main report opens and I get two identical error messages that read, "one or more operators in the filter expression is invalid, for a list of valid operators please refer to the help file".
OR sometimes I get a "Runtime error 2021: one or more operators in the filter expression is invalid" break during execution of the form button's event handler at the line where I set FilterOn=True.
Which error appears seems to vary with the following in a cryptic way that I can't seem to understand:
a)whether I have either report open in design view when I click the form button.
b)what filter expression / FilterOn status is hard-coded on the subreport.
Neither report has any associated VBA code.
Can anyone shed any light on this for me? Any suggestions much appreciated.
Thanks
Rick