1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| Sub filtrerProduits()
Dim critere1, critere2, critere3, critere4 As String
Dim CritereX, critereFinal As String
CritereX = ""
Dim nbrCriteres As Integer
nbrCriteres = 4
critere1 = "aaa" 'IIf(IsNull(Me.produit_1), "", "[produit] like '" & Me.produit_1 & "'")
critere2 = "bbb" 'IIf(IsNull(Me.produit_2), "", "[produit] like '" & Me.produit_2 & "'")
critere3 = "ccc" 'IIf(IsNull(Me.produit_3), "", "[produit] like '" & Me.produit_3 & "'")
critere4 = "" 'IIf(IsNull(Me.produit_4), "", "[produit] like '" & Me.produit_4 & "'")
For J = 1 To nbrCriteres
CritereX = Choose(J, critere1, critere2, critere3, critere4)
CritereX = IIf(Len(CritereX) = 0, "", " [Produit] Like '" & CritereX & "' And")
On Error Resume Next
If J = nbrCriteres Then CritereX = " " & Left(Trim(CritereX), InStrRev(Trim(CritereX), " And") - 1)
critereFinal = IIf(Len(CritereX) = 0, critereFinal, critereFinal & CritereX)
Next J
If Right(critereFinal, 4) Like " And" Then _
critereFinal = Mid(critereFinal, 1, Len(critereFinal) - 4)
Debug.Print Trim(critereFinal)
End Sub |
Partager