Filter Syntax error?

  • Thread starter Thread starter allie357
  • Start date Start date
A

allie357

Please help with the syntax error below:

Syntax error (missing operator) in query expression '([RCName] Like '*'
AND [DeptName]Like'*'[DateEntered]Between #1/1/2004# And #9/12/2006#)'

Code:
 Private Sub Apply_Filter1_Click()

Dim strRCName As String
Dim strDeptName As String
Dim strDate As String
Dim strWhere As String
Dim strNumber As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "rpt_Violations_by_RC_x
Violations") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for RCName field
If IsNull(Me.CboRCName.Value) Then
strRCName = "Like '*'"
Else
strRCName = "='" & Me.CboRCName.Value & "'"
End If
' Build criteria string for DeptName field
If IsNull(Me.cboDeptName.Value) Then
strDeptName = "Like '*'"
Else
strDeptName = "='" & Me.cboDeptName.Value & "'"
End If
' Build the WHERE clause.
strDate = "[DateEntered] Between #" & Me!txtStartDate & _
"# And #" & Me!txtEndDate & "#"



' Combine criteria strings into a WHERE clause for the filter
strWhere = "[RCName] " & strRCName & " AND [DeptName] " &
strDeptName & strDate
' Apply the filter and switch it on

With Reports![rpt_Violations_by_RC_x Violations]
.Filter = strWhere
.FilterOn = True
End With


End Sub
 
You're missing the keyword AND between strDeptName and strDate.

strWhere = "[RCName] " & strRCName & " AND [DeptName] " &
strDeptName & strDate

needs to be

strWhere = "[RCName] " & strRCName & " AND [DeptName] " &
strDeptName & " AND " & strDate
 
Back
Top