Filter Report with OR

T

Tim

I'm trying to apply a filter using the Code below on the Report.Open
event. This checks the values of a forms List Box, where it's
MultiSelect is set to Extended.

If I select only one item from the list box, it works perfectly. When
a select 2 items, the my result is as if it ignores the filter
altogether. However, the filter it puts in the Reports filter
property is: ([Branch_Name] = 'Saginaw' Or 'Ohio') which seems to be
good to me. My code follows:

Dim strWhere As String
Dim lngLen As Long
Dim ctlBranch As Control
Dim ctlEstimator As Control
Dim intCurrentRow As Integer
Dim strEstimator As String
Dim strBranch As String

Set ctlBranch = [Forms]![frmProjectSelector]![lstBranch]
Set ctlEstimator = [Forms]![frmProjectSelector]![lstEstimator]

For intCurrentRow = 0 To ctlBranch.ListCount - 1
If ctlBranch.Selected(intCurrentRow) Then
strBranch = strBranch & "'" & ctlBranch.Column(1,
intCurrentRow) & "' Or "
End If
Next intCurrentRow
lngLen = Len(strBranch) - 4
If lngLen <= 0 Then
strBranch = ""
Else
strBranch = Left$(strBranch, lngLen)
End If

If Not IsNull(strBranch) Then
strWhere = strWhere & "([Branch_Name] = " & strBranch & ") AND
"
End If

lngLen = Len(strWhere) - 5 'Without trailing " AND ".
If lngLen <= 0 Then
strWhere = ""
Else
strWhere = Left$(strWhere, lngLen)
End If

Filter = strWhere
FilterOn = True

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top