Bonjour,
J'ai une base Access partagée par une vingtaine de personnes.
Dans cette base, j'ai un filtre multicritère dans l'en-tête de mon formulaire qui fonctionne à l'aide d'un bouton.
j'ai placé le code suivant Sur l'événement "sur clic" :
Private Sub bouton_filtre_Click()
'filtres sur les champs du formulaire
Ce code fontionne bien même si je reconnais que ce n'est peut-être pas la meilleure syntaxe possible.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 F = "" If Not IsNull(Me.Rmarque) And Me.Rmarque <> "" Then If F <> "" Then F = F & " AND nom_marque LIKE ""*" & Me.Rmarque & "*""" Else F = "nom_marque LIKE ""*" & Me.Rmarque & "*""" End If End If If Not IsNull(Me.Rproduit) And Me.Rproduit <> "" Then If F <> "" Then F = F & " AND nom_produit LIKE ""*" & Me.Rproduit & "*""" Else F = "nom_produit LIKE ""*" & Me.Rproduit & "*""" End If End If If Not IsNull(Me.Rnature_produit) And Me.Rnature_produit <> "" Then If F <> "" Then F = F & " AND nom_nature_produit LIKE ""*" & Me.Rnature_produit & "*""" Else F = "nom_nature_produit LIKE ""*" & Me.Rnature_produit & "*""" End If End If If Not IsNull(Me.Rannonceur) And Me.Rannonceur <> "" Then If F <> "" Then F = F & " AND nom_annonceur LIKE ""*" & Me.Rannonceur & "*""" Else F = "nom_annonceur LIKE ""*" & Me.Rannonceur & "*""" End If End If If Not IsNull(Me.Rtitre_film) And Me.Rtitre_film <> "" Then If F <> "" Then F = F & " AND titre_film LIKE ""*" & Me.Rtitre_film & "*""" Else F = "titre_film LIKE ""*" & Me.Rtitre_film & "*""" End If End If If Not IsNull(Me.Rduree) And Me.Rduree <> "" Then If F <> "" Then F = F & " AND duree_film LIKE ""*" & Me.Rduree & "*""" Else F = "duree_film LIKE ""*" & Me.Rduree & "*""" End If End If If Not IsNull(Me.Rcode_arpp) And Me.Rcode_arpp <> "" Then If F <> "" Then F = F & " AND code_arpp LIKE ""*" & Me.Rcode_arpp & "*""" Else F = "code_arpp LIKE ""*" & Me.Rcode_arpp & "*""" End If End If If Not IsNull(Me.Ride12_film) And Me.Ride12_film <> "" Then If F <> "" Then F = F & " AND ide12_film LIKE ""*" & Me.Ride12_film & "*""" Else F = "ide12_film LIKE ""*" & Me.Ride12_film & "*""" End If End If If Not IsNull(Me.rtitre_oeuvre) And Me.rtitre_oeuvre <> "" Then If F <> "" Then F = F & " AND titre_oeuvre LIKE ""*" & Me.rtitre_oeuvre & "*""" Else F = "titre_oeuvre LIKE ""*" & Me.rtitre_oeuvre & "*""" End If End If If Not IsNull(Me.Rayant_droit) And Me.Rayant_droit <> "" Then If F <> "" Then F = F & " AND nom_ayant_droit LIKE ""*" & Me.Rayant_droit & "*""" Else F = "nom_ayant_droit LIKE ""*" & Me.Rayant_droit & "*""" End If End If If Not IsNull(Me.Rsignature) And Me.Rsignature <> "" Then If F <> "" Then F = F & " AND signature LIKE ""*" & Me.Rsignature & "*""" Else F = "signature LIKE ""*" & Me.Rsignature & "*""" End If End If If Not IsNull(Me.Rhistorique) And Me.Rhistorique <> "" Then If F <> "" Then F = F & " AND DernierDechoix_historique = """ & Me.Rhistorique & """" Else F = "DernierDechoix_historique like """ & Me.Rhistorique & """" End If End If If Not IsNull(Me.Rcocv) And Me.Rcocv <> "" Then If F <> "" Then F = F & " AND ide_12_oeuvre LIKE ""*" & Me.Rcocv & "*""" Else F = "ide_12_oeuvre LIKE ""*" & Me.Rcocv & "*""" End If End If Me.Filter = F Me.FilterOn = True End Sub
Je souhaiterai maintenant remplacer les champs de recherche Rannonceur et Rmarque par un seul champ de recherche (que je nommerai "Rannonceur_mrq" par exemple)
et qui rechercherait a la fois sur la colonne nom_annonceur et nom_marque, tout en fonctionnant avec le reste du filtre.
De sorte que si j'ai 2 critères de recherche, un sur Rannonceur_mrq et un sur Rproduit (par exemple "mc picsou" et "little mac")
le filtre me renvoie tous les enregistrements dont le nom_annonceur ou le nom_marque contient "mc picsou" ET dont le produit contient "little mac"
j'ai testé ce code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 F = "" If Not IsNull(Me.Rannonceur_mrq) And Me.Rannonceur_mrq <> "" Then If F <> "" Then F = F & "nom_annonceur LIKE ""*" & Me.Rannonceur_mrq & "*""" & "or nom_marque Like ""*" & Me.Rannonceur_mrq & "*""" Else F = "nom_annonceur LIKE ""*" & Me.Rannonceur_mrq & "*""" & "or nom_marque Like ""*" & Me.Rannonceur_mrq & "*""" If Not IsNull(Me.Rproduit) And Me.Rproduit <> "" Then If F <> "" Then F = F & " AND nom_produit LIKE ""*" & Me.Rproduit & "*""" Else F = "nom_produit LIKE ""*" & Me.Rproduit & "*""" End If End If If Not IsNull(Me.Rnature_produit) And Me.Rnature_produit <> "" Then If F <> "" Then F = F & " AND nom_nature_produit LIKE ""*" & Me.Rnature_produit & "*""" Else F = "nom_nature_produit LIKE ""*" & Me.Rnature_produit & "*""" End If End If If Not IsNull(Me.Rannonceur) And Me.Rannonceur <> "" Then If F <> "" Then F = F & " AND nom_annonceur LIKE ""*" & Me.Rannonceur & "*""" Else F = "nom_annonceur LIKE ""*" & Me.Rannonceur & "*""" End If End If If Not IsNull(Me.Rtitre_film) And Me.Rtitre_film <> "" Then If F <> "" Then F = F & " AND titre_film LIKE ""*" & Me.Rtitre_film & "*""" Else F = "titre_film LIKE ""*" & Me.Rtitre_film & "*""" End If End If If Not IsNull(Me.Rduree) And Me.Rduree <> "" Then If F <> "" Then F = F & " AND duree_film LIKE ""*" & Me.Rduree & "*""" Else F = "duree_film LIKE ""*" & Me.Rduree & "*""" End If End If If Not IsNull(Me.Rcode_arpp) And Me.Rcode_arpp <> "" Then If F <> "" Then F = F & " AND code_arpp LIKE ""*" & Me.Rcode_arpp & "*""" Else F = "code_arpp LIKE ""*" & Me.Rcode_arpp & "*""" End If End If If Not IsNull(Me.Ride12_film) And Me.Ride12_film <> "" Then If F <> "" Then F = F & " AND ide12_film LIKE ""*" & Me.Ride12_film & "*""" Else F = "ide12_film LIKE ""*" & Me.Ride12_film & "*""" End If End If If Not IsNull(Me.rtitre_oeuvre) And Me.rtitre_oeuvre <> "" Then If F <> "" Then F = F & " AND titre_oeuvre LIKE ""*" & Me.rtitre_oeuvre & "*""" Else F = "titre_oeuvre LIKE ""*" & Me.rtitre_oeuvre & "*""" End If End If If Not IsNull(Me.Rayant_droit) And Me.Rayant_droit <> "" Then If F <> "" Then F = F & " AND nom_ayant_droit LIKE ""*" & Me.Rayant_droit & "*""" Else F = "nom_ayant_droit LIKE ""*" & Me.Rayant_droit & "*""" End If End If If Not IsNull(Me.Rsignature) And Me.Rsignature <> "" Then If F <> "" Then F = F & " AND signature LIKE ""*" & Me.Rsignature & "*""" Else F = "signature LIKE ""*" & Me.Rsignature & "*""" End If End If If Not IsNull(Me.Rhistorique) And Me.Rhistorique <> "" Then If F <> "" Then F = F & " AND DernierDechoix_historique = """ & Me.Rhistorique & """" Else F = "DernierDechoix_historique like """ & Me.Rhistorique & """" End If End If If Not IsNull(Me.Rcocv) And Me.Rcocv <> "" Then If F <> "" Then F = F & " AND ide_12_oeuvre LIKE ""*" & Me.Rcocv & "*""" Else F = "ide_12_oeuvre LIKE ""*" & Me.Rcocv & "*""" End If End If Me.Filter = F Me.FilterOn = True
avec le 1er critère il fonctionne.
En revanche quand je rajoute le 2ème critère, il me renvoie bien tous les enregistrements dont le champ "nom_annonceur" ou le champ "nom_marque" contiennent "mc picsou" mais parmi ceux là, il me renvoie également ceux qui ne contiennent pas le 2ème critère "little mac".
Je suppose que c'est un problème de logique. Quelqu'un aurait une idée s'il vous plait?
D'avance merci pour votre aide,
Thierry
P.s Je précise que je ne suis pas développeur de métier et plutôt néophyte.
Partager