OVH Cloud OVH Cloud

critère de choix multiples

2 réponses
Avatar
le meruvien
Bonjour les pros !
Une procedure que j'avais fait pour imprimer des etiquettes marchait tres
bien, mais aujourdhui, je veut utiliser cette procedure pour afficher des
données dans un formulaire tableau, ça marche pas !!
qui peut m'aider ?
Voila mon truc :
J'ai donc un formulaire "liste", et je veut afficher selon 4 critères <>
1) l'année "toute" ou une année choisie
2) l'altitude "toute" ou une choisie
3) le departement "tous" ou un entré
4) la route "toute" ou une selectionnée dans une LD
MERCI d'avance


************************
Private Sub VALIDER_Click()
Dim strfiltre As String
Dim strStatut As String
Dim avarMotsClefs As Variant
Dim varMotClef As Variant
Dim e As Report, aql As String
SQL = "": strfiltre = ""
SQL = SQL & "select distinct [annee],altitude,departement,route from [rqt
liste]"
SQL = SQL & "inner join [rqt liste]"
On Error Resume Next
If choix1 = "toute" Then choix1 = ""
If choix2 = "toute" Then choix2 = ""
if choix3= "Tous" Then choix3 = ""
If choix4 = "toute" Then choix4 = ""
' Filtre sur l'année
If Not IsNull(Me.choix1) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([annee]='" & Me.choix1 & "')"
End If
' Filtre sur l'altitude
If Not IsNull(Me.choix2) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([altitude]='" & Me.choix2 & "')"
End If
' Filtre sur le département
If Not IsNull(Me.choix3) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([departement]='" & Me.choix3 & "')"
End If
' Filtre sur les routes
If Not IsNull(Me.choix4) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([route]=" & Me.choix4 & ")"
End If
SQL = SQL & "where " & strfiltre & ";"
Set e = Forms![liste]
e.RecordSource = SQL
DoCmd.OpenForm "liste", acNormal
DoCmd.Close acForm, "selection recherche"
End Sub
*************************

2 réponses

Avatar
Ilan
Bonjour,
Heu.... bizarre les lignes suivantes
SQL = SQL & "select distinct [annee],altitude,departement,route from [rqt
liste]"
SQL = SQL & "inner join [rqt liste]"
SQL = SQL & "where " & strfiltre & ";"


ca donne SELECT DISTINCT .... FROM [rqt liste]inner join [rqt liste]where

essaie peut-etre le code suivant qui ne devrait marcher que si
Choix1 à Choix4 sont bien les noms des controls de ton formulaire.

Private Sub VALIDER_Click()
Dim strfiltre As String
Dim strStatut As String
Dim avarMotsClefs As Variant
Dim varMotClef As Variant
Dim e As Report, aql As String
Dim Champ(3, 0) As String, choix As String
Dim SepCar As Integer
Champ(0) = "[annee]-string"
Champ(1) = "[altitude]-string"
Champ(2) = "[departement]-string"
Champ(3) = "[route]-numeric"
SQL = ""
strfiltre = ""
SQL = "SELECT DISTINCT [annee],altitude,departement,route FROM [rqt liste]"
On Error Resume Next
For i = 1 To 4
choix = Form.Controls("choix" & i).Value
If choix <> "" And choix <> "toute" And choix <> "Tous" Then
If strfiltre = "" Then
strfiltre = " WHERE "
Else
strfiltre = strfiltre & " AND "
End If
SepCar = InStr(1, Champ(i - 1), "-")
strfiltre = strfiltre & Left(Champ(i - 1), SepCar - 1)
If Mid(Champ(i - 1), SepCar + 1) = "string" Then strfiltre =
strfiltre & " = '" & choix & "'"
If Mid(Champ(i - 1), SepCar + 1) = "numeric" Then strfiltre =
strfiltre & " = " & choix
End If
End If
Next i
SQL = SQL & strfiltre & ";"
DoCmd.OpenForm "liste", acDesign
Forms("liste").RecordSource = SQL
DoCmd.OpenForm "liste", acNormal
DoCmd.Close acForm, "selection recherche"
End Sub



Bonjour les pros !
Une procedure que j'avais fait pour imprimer des etiquettes marchait tres
bien, mais aujourdhui, je veut utiliser cette procedure pour afficher des
données dans un formulaire tableau, ça marche pas !!
qui peut m'aider ?
Voila mon truc :
J'ai donc un formulaire "liste", et je veut afficher selon 4 critères <>
1) l'année "toute" ou une année choisie
2) l'altitude "toute" ou une choisie
3) le departement "tous" ou un entré
4) la route "toute" ou une selectionnée dans une LD
MERCI d'avance


************************
Private Sub VALIDER_Click()
Dim strfiltre As String
Dim strStatut As String
Dim avarMotsClefs As Variant
Dim varMotClef As Variant
Dim e As Report, aql As String
SQL = "": strfiltre = ""
SQL = SQL & "select distinct [annee],altitude,departement,route from [rqt
liste]"
SQL = SQL & "inner join [rqt liste]"
On Error Resume Next
If choix1 = "toute" Then choix1 = ""
If choix2 = "toute" Then choix2 = ""
if choix3= "Tous" Then choix3 = ""
If choix4 = "toute" Then choix4 = ""
' Filtre sur l'année
If Not IsNull(Me.choix1) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([annee]='" & Me.choix1 & "')"
End If
' Filtre sur l'altitude
If Not IsNull(Me.choix2) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([altitude]='" & Me.choix2 & "')"
End If
' Filtre sur le département
If Not IsNull(Me.choix3) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([departement]='" & Me.choix3 & "')"
End If
' Filtre sur les routes
If Not IsNull(Me.choix4) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([route]=" & Me.choix4 & ")"
End If
SQL = SQL & "where " & strfiltre & ";"
Set e = Forms![liste]
e.RecordSource = SQL
DoCmd.OpenForm "liste", acNormal
DoCmd.Close acForm, "selection recherche"
End Sub
*************************





Avatar
le meruvien
bonjour, et merci, t'inquéte pas, j'ai trouvé un exemple dans le livre
"reference access 2000", et ça marche tres bien
merci tout de meme


"Ilan" a écrit dans le message de news:

Bonjour,
Heu.... bizarre les lignes suivantes
SQL = SQL & "select distinct [annee],altitude,departement,route from [rqt
liste]"
SQL = SQL & "inner join [rqt liste]"
SQL = SQL & "where " & strfiltre & ";"


ca donne SELECT DISTINCT .... FROM [rqt liste]inner join [rqt liste]where

essaie peut-etre le code suivant qui ne devrait marcher que si
Choix1 à Choix4 sont bien les noms des controls de ton formulaire.

Private Sub VALIDER_Click()
Dim strfiltre As String
Dim strStatut As String
Dim avarMotsClefs As Variant
Dim varMotClef As Variant
Dim e As Report, aql As String
Dim Champ(3, 0) As String, choix As String
Dim SepCar As Integer
Champ(0) = "[annee]-string"
Champ(1) = "[altitude]-string"
Champ(2) = "[departement]-string"
Champ(3) = "[route]-numeric"
SQL = ""
strfiltre = ""
SQL = "SELECT DISTINCT [annee],altitude,departement,route FROM [rqt
liste]"
On Error Resume Next
For i = 1 To 4
choix = Form.Controls("choix" & i).Value
If choix <> "" And choix <> "toute" And choix <> "Tous" Then
If strfiltre = "" Then
strfiltre = " WHERE "
Else
strfiltre = strfiltre & " AND "
End If
SepCar = InStr(1, Champ(i - 1), "-")
strfiltre = strfiltre & Left(Champ(i - 1), SepCar - 1)
If Mid(Champ(i - 1), SepCar + 1) = "string" Then strfiltre > strfiltre & " = '" & choix & "'"
If Mid(Champ(i - 1), SepCar + 1) = "numeric" Then strfiltre > strfiltre & " = " & choix
End If
End If
Next i
SQL = SQL & strfiltre & ";"
DoCmd.OpenForm "liste", acDesign
Forms("liste").RecordSource = SQL
DoCmd.OpenForm "liste", acNormal
DoCmd.Close acForm, "selection recherche"
End Sub



Bonjour les pros !
Une procedure que j'avais fait pour imprimer des etiquettes marchait tres
bien, mais aujourdhui, je veut utiliser cette procedure pour afficher des
données dans un formulaire tableau, ça marche pas !!
qui peut m'aider ?
Voila mon truc :
J'ai donc un formulaire "liste", et je veut afficher selon 4 critères <>
1) l'année "toute" ou une année choisie
2) l'altitude "toute" ou une choisie
3) le departement "tous" ou un entré
4) la route "toute" ou une selectionnée dans une LD
MERCI d'avance


************************
Private Sub VALIDER_Click()
Dim strfiltre As String
Dim strStatut As String
Dim avarMotsClefs As Variant
Dim varMotClef As Variant
Dim e As Report, aql As String
SQL = "": strfiltre = ""
SQL = SQL & "select distinct [annee],altitude,departement,route from [rqt
liste]"
SQL = SQL & "inner join [rqt liste]"
On Error Resume Next
If choix1 = "toute" Then choix1 = ""
If choix2 = "toute" Then choix2 = ""
if choix3= "Tous" Then choix3 = ""
If choix4 = "toute" Then choix4 = ""
' Filtre sur l'année
If Not IsNull(Me.choix1) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([annee]='" & Me.choix1 & "')"
End If
' Filtre sur l'altitude
If Not IsNull(Me.choix2) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([altitude]='" & Me.choix2 & "')"
End If
' Filtre sur le département
If Not IsNull(Me.choix3) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([departement]='" & Me.choix3 & "')"
End If
' Filtre sur les routes
If Not IsNull(Me.choix4) Then
If strfiltre <> "" Then strfiltre = strfiltre & " AND "
strfiltre = strfiltre & "([route]=" & Me.choix4 & ")"
End If
SQL = SQL & "where " & strfiltre & ";"
Set e = Forms![liste]
e.RecordSource = SQL
DoCmd.OpenForm "liste", acNormal
DoCmd.Close acForm, "selection recherche"
End Sub
*************************