A
allie357
Below I am posting my code for a form that should help me filter a
report. I am getting a syntax error here:
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[RCName] " & strRCName & " AND [DeptName] " & strDeptName
& " AND [CountofPolicy] " & strNumber & "([EnteredOn] >= " &
Format(Me.txtStartDate, conJetDate) & ") AND "([EnteredOn] < " &
Format(Me.txtEndDate + 1, conJetDate) & ")
The filter needs to take a number from the count of Policy field and
return results >= the number entered into the field and the start date
and end date need to evaluate the DateEntered field. I am sort of new
to the filter concept in VBA so I need help.
report. I am getting a syntax error here:
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[RCName] " & strRCName & " AND [DeptName] " & strDeptName
& " AND [CountofPolicy] " & strNumber & "([EnteredOn] >= " &
Format(Me.txtStartDate, conJetDate) & ") AND "([EnteredOn] < " &
Format(Me.txtEndDate + 1, conJetDate) & ")
The filter needs to take a number from the count of Policy field and
return results >= the number entered into the field and the start date
and end date need to evaluate the DateEntered field. I am sort of new
to the filter concept in VBA so I need help.
Code:
Option Compare Database
Option Explicit
Private Sub CboRCName_AfterUpdate()
Me!cboDeptName.Requery
End Sub
Private Sub CboRCName_Change()
'Set value of combo box equal to an empty string
Me!cboDeptName.Value = ""
End Sub
Private Sub FilterReport1_Click()
Dim strRCName As String
Dim strDeptName As String
Dim strStartDate As String
Dim strEndDate As String
Const conJetDate = "\#mm\/dd\/yyyy\#"
'The format expected for dates in a JET query string.
Dim strNumber As String
Dim strFilter 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 criteria string for StartDate field
If IsNull(Me.txtStartDate.Value) Then
strStartDate = "Like '*'"
Else
strStartDate = "='" & Me.txtStartDate.Value & "'"
End If
' Build criteria string for EndDate field
If IsNull(Me.txtEndDate.Value) Then
strEndDate = "Like '*'"
Else
strEndDate = "='" & Me.txtEndDate.Value & "'"
End If
' Build criteria string for txtNumber field
If IsNull(Me.txtnumber.Value) Then
strNumber = "Like '*'"
Else
strNumber = ">='" & Me.txtnumber.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[RCName] " & strRCName & " AND [DeptName] " & strDeptName
& " AND [CountofPolicy] " & strNumber & "([EnteredOn] >= " &
Format(Me.txtStartDate, conJetDate) & ") AND "([EnteredOn] < " &
Format(Me.txtEndDate + 1, conJetDate) & ")
' Apply the filter and switch it on
With Reports![rpt_Violations_by_RC_x Violations]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![rpt_Violations_by_RC_x Violations].FilterOn = False
End Sub