Thank you in advance for your help.
I have a filter that uses multiple criteria to produce a report. It works great with one exception. When the Between function is followed by another criteria (such as "Action" required) I get an error message: Run-time error '3075': Syntax error (missing operator) in query expression 'SaleDate Between [txtSaleFrom] And [txtSaleTo][Action] =-1'. Any other combination of criteria works great. Am I missing an "AND"?
The first part of the code for the filter is:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null ' Main filter
' Check for Sale Dates within the range.
If Me.txtSaleFrom > "" Then
varWhere = varWhere & "[SaleDate] Between [txtSaleFrom] And [txtSaleTo]"
End If
' Check for LIKE Product Type
If Me.cboProductType > "" Then
varWhere = varWhere & "[ProductType] LIKE """ & Me.cboProductType & "*"" AND "
End If
' Check for LIKE Product Number
If Me.txtProductNo > "" Then
varWhere = varWhere & "[ProductNo] LIKE """ & Me.txtProductNo & "*"" AND "
End If
' Check for Action Required
If Me.chkAction < 0 Then
varWhere = varWhere & "[Action] = " & Me.chkAction & " AND "
End If
I have a filter that uses multiple criteria to produce a report. It works great with one exception. When the Between function is followed by another criteria (such as "Action" required) I get an error message: Run-time error '3075': Syntax error (missing operator) in query expression 'SaleDate Between [txtSaleFrom] And [txtSaleTo][Action] =-1'. Any other combination of criteria works great. Am I missing an "AND"?
The first part of the code for the filter is:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null ' Main filter
' Check for Sale Dates within the range.
If Me.txtSaleFrom > "" Then
varWhere = varWhere & "[SaleDate] Between [txtSaleFrom] And [txtSaleTo]"
End If
' Check for LIKE Product Type
If Me.cboProductType > "" Then
varWhere = varWhere & "[ProductType] LIKE """ & Me.cboProductType & "*"" AND "
End If
' Check for LIKE Product Number
If Me.txtProductNo > "" Then
varWhere = varWhere & "[ProductNo] LIKE """ & Me.txtProductNo & "*"" AND "
End If
' Check for Action Required
If Me.chkAction < 0 Then
varWhere = varWhere & "[Action] = " & Me.chkAction & " AND "
End If