Going with Sudonim's suggestion:
dim strFilter as String
const cAnd as String = " AND "
If ([CmbBrn] = 0 And [CmbAM] = 0 And [CmbSls] = "") Then
Me.FilterOn = False
Else
If [CmbBrn] <> 0 Then
strFilter = "[Branch_num]='" & [CmbBrn] & "'"
End If
If [CmbAM] <> 0 Then
strFilter = strFilter & cAnd & "[Territory_num]='" & [CmbAM] & "'"
End If
If [CmbSls] <> "" Then
strFilter = strFilter & cAnd & " [Salesman_num]IN(" & [CmbSls] & ")"
End If
If Left(strFilter, len(cAnd)) = cAnd then
' Drop the leading AND if there is one
strFilter = mid(strFilter, len(cAnd) + 1)
End If
me.Filter = strFilter ' I can't offhand remember whther setting this property automatically sets FilterOn = True
End If
Main Topics
Browse All Topics





by: SudonimPosted on 2009-05-06 at 00:37:58ID: 24311952
does the value in the combo contain multipoe fields - or is there a list box which the user can do multiple select on?
if its a combo showing multiple values, you'll need to build up a filter string with a where clause with "or" for each value..
also your nested IF is a night mare...
why not declare a string
dim strFilter as string...
strFilter = ""
then in each secion for the 3 combo's add new filter stuff to the string with and's or Or's
strFilter = strFilter " and [Salesman_num]IN(" & [CmbSls] & ")"
etc..
then at the end set
me.filter = strFilter