Dear Query Expert.
I have a query with a date field and I am trying to implement the following logic in the criteria. Date Criteria = CustomerMonthlyWasteReportDate()
Both Functions cause and error in the Criteria when I run the query.
Error Message: DataType Mismatch in the Criteria Expression.
The interesting fact is when I manually put in the results of these functions it works. I used the Variant as the return type.
How do I achieve what I want. Thanks.
I have a query with a date field and I am trying to implement the following logic in the criteria. Date Criteria = CustomerMonthlyWasteReportDate()
Both Functions cause and error in the Criteria when I run the query.
Error Message: DataType Mismatch in the Criteria Expression.
The interesting fact is when I manually put in the results of these functions it works. I used the Variant as the return type.
How do I achieve what I want. Thanks.
Code:
Public Function CustomerMonthlyWasteReportDate() As Variant
Dim strDate As Variant
If Forms![CustomerMonthlyWasteReport]![ReportType] = 1 Then
strDate = "Between #" & CDate(Forms![CustomerMonthlyWasteReport]![FromMonth]) & "# And #" & CDate(Forms![CustomerMonthlyWasteReport]![ToMonth]) & "#"
Else
strDate = "Between " & Forms![CustomerMonthlyWasteReport]![FromMan] & " and " & Forms![CustomerMonthlyWasteReport]![ToMan]
End If
CustomerMonthlyWasteReportDate = strDate
End Function
Public Function CustomerMonthlyWasteReportDate2() As Variant
Dim strDate As Variant
If Forms![CustomerMonthlyWasteReport]![ReportType] = 1 Then
strDate = ">= #" & CDate(Forms![CustomerMonthlyWasteReport]![FromMonth]) & "# And <= #" & CDate(Forms![CustomerMonthlyWasteReport]![ToMonth]) & "#"
Else
strDate = "Between " & Forms![CustomerMonthlyWasteReport]![FromMan] & " and " & Forms![CustomerMonthlyWasteReport]![ToMan]
End If
CustomerMonthlyWasteReportDate2 = strDate
End Function