Bonjour à tous,
Existe t'il un code comme End If, Else... pour dire "ça" ou "ça" ??
Merci
Bonjour à tous,
Existe t'il un code comme End If, Else... pour dire "ça" ou "ça" ??
Merci
Bonjour
OR et pour "et" c'est AND
Un truc quand tu cherches quelque chose essaye de le traduire en Anglais
Starec
Merci mais j'arrive pas le faire fonctionner ...
J'ai marqué ça:
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 Private Sub RefreshQuery() Dim SQL As String Dim SQLWhere As String SQL = "SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 " If Not Me.chkpays Then SQL = SQL & "And Entreprises!Pays = '" & Me.cmbpays & "' " End If If Not Me.chkType Then SQL = SQL & "And Entreprises!Type = '" & Me.cmbtype & "' " End If If Not Me.chkfilconso Then SQL = SQL & "And Entreprises!Fil_consommé = '" & Me.cmbfilconso & "' " End If If Not Me.chkfildistri Then SQL = SQL & "And Entreprises!Fil_distribué = '" & Me.cmbfildistri & "' " End If If Not Me.chknom Then SQL = SQL & "And Entreprises!Nom like '*" & Me.txtnom & "*' " Or SQL = SQL & "And Entreprises!Nom = '" & Me.cmbnom & "' " End If SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1)) SQL = SQL & ";" 'Me.lblStats.Caption = DCount("*", "Entreprises", SQLWhere) & "/" & DCount("*", "Entreprises") Me.lstResults.RowSource = SQL Me.lstResults.Requery End Sub
Re
Quand on veut utiliser une fonction comme IF on regarde l'aide, ce n'est par OR dans ce cas là, l'aide et l'exemple de l'aide te donnera un exemple.
Dans ton IF c'est un Else
Starec
Merci beaucoup pour tes réponses, mais je n'y arrive toujours pas![]()
En fait voila ce que je veux faire:
J'ai créer un formulaire de recherche multi critères.
Et j'aimerais que lorsque l'on clique dans la checkbox "chknom" ça fasse apparaitre 2 choses: 1 champs de text où l'on tape une lettre pour rechercher et 1 liste modifiable ==> tout ça pour permettre à l'utilisateur de choisir la façon dont il va rechercher. Jusque là tout va bien...
Mais quand les 2 s'affichent, après il n'y en a qu'un sur les deux qui marche... ici c'est le txtnom qui marche.
Et donc j'aimerai que l'utilisateur ait le choix de rechercher soit par mot-clé / lettre-clé, soit dans une liste...
Voila mon code actuel...
Merci encore et vraiment désolé de pas être doué !!
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 Option Compare Database Private Sub chknom_Click() If Me.chknom Then Me.cmbnom.Visible = False Me.txtnom.Visible = False Else Me.cmbnom.Visible = True Me.txtnom.Visible = True End If RefreshQuery End Sub Private Sub chkpays_Click() If Me.chkpays Then Me.cmbpays.Visible = False Else Me.cmbpays.Visible = True End If RefreshQuery End Sub Private Sub chktype_Click() If Me.chkType Then Me.cmbtype.Visible = False Else Me.cmbtype.Visible = True End If RefreshQuery End Sub Private Sub chkfilconso_Click() If Me.chkfilconso Then Me.cmbfilconso.Visible = False Else Me.cmbfilconso.Visible = True End If RefreshQuery End Sub Private Sub chkfildistri_Click() If Me.chkfildistri Then Me.cmbfildistri.Visible = False Else Me.cmbfildistri.Visible = True End If RefreshQuery End Sub Private Sub cmbpays_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbtype_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbfilconso_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbfildistri_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbnom_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub txtnom_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub Form_Load() Dim ctl As Control For Each ctl In Me.Controls Select Case Left(ctl.Name, 3) Case "chk" ctl.Value = -1 Case "lbl" ctl.Caption = "- * - * -" Case "cmb" ctl.Visible = False End Select Next ctl Me.lstResults.RowSource = "SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises;" Me.lstResults.Requery End Sub Private Sub RefreshQuery() Dim SQL As String Dim SQLWhere As String SQL = "SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 " If Not Me.chkpays Then SQL = SQL & "And Entreprises!Pays = '" & Me.cmbpays & "' " End If If Not Me.chkType Then SQL = SQL & "And Entreprises!Type = '" & Me.cmbtype & "' " End If If Not Me.chkfilconso Then SQL = SQL & "And Entreprises!Fil_consommé = '" & Me.cmbfilconso & "' " End If If Not Me.chkfildistri Then SQL = SQL & "And Entreprises!Fil_distribué = '" & Me.cmbfildistri & "' " End If If Not Me.chknom Then SQL = SQL & "And Entreprises!Nom like '*" & Me.txtnom & "*' " Else SQL = SQL & "And Entreprises!Nom = '" & Me.cmbnom & "' " End If SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1)) SQL = SQL & ";" Me.lstResults.RowSource = SQL Me.lstResults.Requery End Sub Private Sub txtnom_Enter() RefreshQuery End Sub Private Sub Bouton_Click() On Error GoTo Err_Bouton_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "Formulaire_Entreprises" DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_Bouton_Click: Exit Sub Err_Bouton_Click: MsgBox Err.Description Resume Exit_Bouton_Click End Sub
Merci
Bonjour
Fait un debug.print pour voir ce que fais ta requête.
Avant
Ecrit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Me.lstResults.RowSource = SQL Me.lstResults.Requery
ou
Code : Sélectionner tout - Visualiser dans une fenêtre à part Debug.print SQL
Pour voir si ta chaine est correcte en testant tous les cas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part MsgBox SQL
Starec
BOn bah j'dois vraiment être nul parce que j'ai fais un copier coller de Debug.print SQL mais je comprend pas ce qu'il est censé se passer...
J'suis censé faire quoi une fois que j'ai marqué ça ?
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183 Option Compare Database Private Sub chknom_Click() If Me.chknom Then Me.cmbnom.Visible = False Me.txtnom.Visible = False Else Me.cmbnom.Visible = True Me.txtnom.Visible = True End If RefreshQuery End Sub Private Sub chkpays_Click() If Me.chkpays Then Me.cmbpays.Visible = False Else Me.cmbpays.Visible = True End If RefreshQuery End Sub Private Sub chktype_Click() If Me.chkType Then Me.cmbtype.Visible = False Else Me.cmbtype.Visible = True End If RefreshQuery End Sub Private Sub chkfilconso_Click() If Me.chkfilconso Then Me.cmbfilconso.Visible = False Else Me.cmbfilconso.Visible = True End If RefreshQuery End Sub Private Sub chkfildistri_Click() If Me.chkfildistri Then Me.cmbfildistri.Visible = False Else Me.cmbfildistri.Visible = True End If RefreshQuery End Sub Private Sub cmbpays_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbtype_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbfilconso_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbfildistri_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub cmbnom_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub txtnom_BeforeUpdate(Cancel As Integer) RefreshQuery End Sub Private Sub Form_Load() Dim ctl As Control For Each ctl In Me.Controls Select Case Left(ctl.Name, 3) Case "chk" ctl.Value = -1 Case "lbl" ctl.Caption = "- * - * -" Case "cmb" ctl.Visible = False End Select Next ctl Me.lstResults.RowSource = "SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises;" Me.lstResults.Requery End Sub Private Sub RefreshQuery() Dim SQL As String Dim SQLWhere As String SQL = "SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 " If Not Me.chkpays Then SQL = SQL & "And Entreprises!Pays = '" & Me.cmbpays & "' " End If If Not Me.chkType Then SQL = SQL & "And Entreprises!Type = '" & Me.cmbtype & "' " End If If Not Me.chkfilconso Then SQL = SQL & "And Entreprises!Fil_consommé = '" & Me.cmbfilconso & "' " End If If Not Me.chkfildistri Then SQL = SQL & "And Entreprises!Fil_distribué = '" & Me.cmbfildistri & "' " End If If Not Me.chknom Then SQL = SQL & "And Entreprises!Nom like '*" & Me.txtnom & "*' " Else SQL = SQL & "And Entreprises!Nom = '" & Me.cmbnom & "' " End If SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1)) SQL = SQL & ";" Debug.Print SQL Me.lstResults.RowSource = SQL Me.lstResults.Requery End Sub Private Sub txtnom_Enter() RefreshQuery End Sub Private Sub Bouton_Click() On Error GoTo Err_Bouton_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "Formulaire_Entreprises" DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_Bouton_Click: Exit Sub Err_Bouton_Click: MsgBox Err.Description Resume Exit_Bouton_Click End Sub
Encore désolé...![]()
Re
Tu ouvres ton éditeur VB
Dans Affichage tu sélectionne Fenêtre Exécution et tu verras le résultat, sinons fait avec le MsgBox.
Starec
Voila ce que ça me donne:
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 SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom = '' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '*b*' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '*b*' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom = '' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom = '' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '*b*' ; SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom = '' ;
Re
A toi de voir si pour chaque cas ta requête donne ce que tu veux, et corrige en conséquence.
Starec
Alors,
ça ça ne marche pas:
Et ça ça marche:
Code : Sélectionner tout - Visualiser dans une fenêtre à part SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '**' ;
La recherche par mot clé marche mais pas celle par choix dans la liste...
Code : Sélectionner tout - Visualiser dans une fenêtre à part SELECT code_entreprise, Nom, Pays, Type, Fil_consommé, Fil_distribué FROM Entreprises Where Entreprises!code_entreprise <> 0 And Entreprises!Nom like '*b*' ;
Je viens de me rendre compte d'un truc:
QUand je veux faire une recherche par choix dans la liste, ça marche (photo 1) et si je met en meme temps une recherche par lettre, si je mets une lettre qui est présente dans le mot, ça marche (photo 2), mais dès que je mets une lettre qui n'est pas présente dans le mot, tout s'efface(photo 3).
Et si je mets une seule lettre sans choisir quelquechose dans la liste (ce que j'aimerais reussir à faire) ça ne marche pas ...(photo 4)
![]()
Partager