IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Access Discussion :

Recherche multi-critères


Sujet :

Access

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut Recherche multi-critères
    bonjour,
    suite à la mise en place d'un form muti-critères (issu du tuto de cafeine...qui fonctionne à merveille )
    je souhaite rajouter un tri sur un champ oui/non en case à cocher sans association avec une cmbox
    cad que le tri s'effectue uniquement sur les cases cochées...
    dans l'exemple de cafeine, que dois-je modifier??


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Private Sub chkResume_Click()
     
    If Me.chkResume Then
        Me.txtRechResume.Visible = False
    Else
        Me.txtRechResume.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
    Merci

  2. #2
    Expert éminent
    Avatar de cafeine
    Inscrit en
    Juin 2002
    Messages
    3 904
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 3 904
    Points : 6 781
    Points
    6 781
    Par défaut
    Tu dois modifier la Sub RefreshQuery() pour qu'elle ajoute à la chaine SQL, une clause Order By après la clause Where.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    If Me.chkTri Then
       SQL = SQL & "ORDER BY [MaTable]![MonChampTrié] ASC;"
    End If
    ASC tri croissant
    DESC tri décroissant

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    après la clause Where...mais comment??
    ci joint mon code pour plus de précision
    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
     
    Option Compare Database
    Option Explicit
     
     
    Private Sub chkDC_Click()
    If Me.chkDC Then
       SQL = SQL & "ORDER BY [PATIENTS]![DC] ASC;"
    End If
     
    End Sub
     
    Private Sub chkNomEtude_Click()
     
    If Me.chkNomEtude Then
        Me.cmbRechNomEtude.Visible = False
    Else
        Me.cmbRechNomEtude.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
    Private Sub chkNomInvestigateur_Click()
     
    If Me.chkNomInvestigateur Then
        Me.cmbRechNomInvestigateur.Visible = False
    Else
        Me.cmbRechNomInvestigateur.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
     
    Private Sub chkTYPEDEPATHOLOGIE_Click()
     
    If Me.chkTYPEDEPATHOLOGIE Then
        Me.cmbRechTYPEDEPATHOLOGIE.Visible = False
    Else
        Me.cmbRechTYPEDEPATHOLOGIE.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechNomEtude_BeforeUpdate(Cancel As Integer)
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechNomInvestigateur_BeforeUpdate(Cancel As Integer)
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechTYPEDEPATHOLOGIE_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 "txt"
                ctl.Visible = False
                ctl.Value = ""
     
            Case "cmb"
                ctl.Visible = False
     
        End Select
    Next ctl
     
    Me.lstResults.RowSource = "SELECT Reclin, NOM,PRENOM, NOMETUDE, NOMINVESTIGATEUR, TYPEDEPATHOLOGIE FROM Patients;"
    Me.lstResults.Requery
     
    End Sub
    Private Sub RefreshQuery()
     
    Dim SQL As String
    Dim SQLWhere As String
     
    SQL = "SELECT Reclin, NOM, PRENOM, NOMETUDE, NOMINVESTIGATEUR, TYPEDEPATHOLOGIE FROM Patients Where Patients!Reclin <> 0 "
     
     
    If Not Me.chkNomEtude Then
        If Len(chkNomEtude) > 0 Then
        SQL = SQL & "And Patients!NomEtude = '" & Me.cmbRechNomEtude & "' "
        End If
    End If
     
    If Not Me.chkNomInvestigateur Then
        If Len(chkNomInvestigateur) > 0 Then
        SQL = SQL & "And Patients!NomInvestigateur = '" & Me.cmbRechNomInvestigateur & "' "
        End If
    End If
     
     
    If Not Me.chkTYPEDEPATHOLOGIE Then
        If Len(chkTYPEDEPATHOLOGIE) > 0 Then
        SQL = SQL & "And Patients!TYPEDEPATHOLOGIE = '" & Me.cmbRechTYPEDEPATHOLOGIE & "' "
        End If
    End If
     
     
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
     
    SQL = SQL & ";"
     
    Me.lblStats.Caption = DCount("*", "Patients", SQLWhere) & " / " & DCount("*", "Patients")
    Me.lstResults.RowSource = SQL
    Me.lstResults.Requery
     
    Dim Nbtotal, Resul As Integer
     
    Nbtotal = DCount("*", "Patients")
    Resul = DCount("*", "Patients", SQLWhere)
    Me.Texte50 = (Resul / Nbtotal) * 100
    End Sub
     
    Private Sub Form_Open(Cancel As Integer)
    DoCmd.Maximize
    End Sub
     
    Private Sub lstResults_DblClick(Cancel As Integer)
     
    DoCmd.OpenForm "FORM PATIENTSMULTCRIT", acNormal, , "[RECLIN] = " & Me.lstResults
     
     
     
    End Sub
    la modif porte sur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Private Sub chkDC_Click() 
    If Me.chkDC Then 
       SQL = SQL & "ORDER BY [PATIENTS]![DC] ASC;" 
    End If 
     
    End Sub

  4. #4
    Expert éminent
    Avatar de cafeine
    Inscrit en
    Juin 2002
    Messages
    3 904
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 3 904
    Points : 6 781
    Points
    6 781
    Par défaut
    non non non .. j'ai dit de modifier uniquement RefreshQuery()

    code sur le clic de ta case à cocher ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Private Sub chkDC_Click()
       RefreshQuery
    End Sub
    puis le code de RefreshQuery()
    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
    'en haut de la fonction
    Dim SQLOrder As String
    ...
    ' ton code avant
    If Not Me.chkTYPEDEPATHOLOGIE Then
        If Len(chkTYPEDEPATHOLOGIE) > 0 Then
        SQL = SQL & "And Patients!TYPEDEPATHOLOGIE = '" & Me.cmbRechTYPEDEPATHOLOGIE & "' "
        End If
    End If
     
    ' le code que je t'ai fourni
    If Me.chkTri Then
       SQLOrder = " ORDER BY [PATIENTS]![DC]  ASC;"
    End If
     
    ' reprise de ton code
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
     
    ' ici j'ajoute la clause Order By
    SQL = SQL & SQLOrder
     
    Me.lblStats.Caption = DCount("*", "Patients", SQLWhere) & " / " & DCount("*", "Patients")
    Me.lstResults.RowSource = SQL
    Me.lstResults.Requery

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    j'ai tout bien fait...
    mais erreur de syntaxe dans : SQL = SQL & SQLOrder ";"

    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
     
    Option Compare Database
    Option Explicit
     
     
    Private Sub chkDC_Click()
       RefreshQuery
    End Sub
     
    Private Sub chkNomEtude_Click()
     
    If Me.chkNomEtude Then
        Me.cmbRechNomEtude.Visible = False
    Else
        Me.cmbRechNomEtude.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
    Private Sub chkNomInvestigateur_Click()
     
    If Me.chkNomInvestigateur Then
        Me.cmbRechNomInvestigateur.Visible = False
    Else
        Me.cmbRechNomInvestigateur.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
     
    Private Sub chkTYPEDEPATHOLOGIE_Click()
     
    If Me.chkTYPEDEPATHOLOGIE Then
        Me.cmbRechTYPEDEPATHOLOGIE.Visible = False
    Else
        Me.cmbRechTYPEDEPATHOLOGIE.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechNomEtude_BeforeUpdate(Cancel As Integer)
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechNomInvestigateur_BeforeUpdate(Cancel As Integer)
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechTYPEDEPATHOLOGIE_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 "txt"
                ctl.Visible = False
                ctl.Value = ""
     
            Case "cmb"
                ctl.Visible = False
     
        End Select
    Next ctl
     
    Me.lstResults.RowSource = "SELECT Reclin, NOM,PRENOM, NOMETUDE, NOMINVESTIGATEUR, TYPEDEPATHOLOGIE, FROM Patients;"
    Me.lstResults.Requery
     
    End Sub
    Private Sub RefreshQuery()
    Dim SQLOrder As String
    Dim SQL As String
    Dim SQLWhere As String
     
    SQL = "SELECT Reclin, NOM, PRENOM, NOMETUDE, NOMINVESTIGATEUR, TYPEDEPATHOLOGIE, FROM Patients Where Patients!Reclin <> 0 "
     
     
    If Not Me.chkNomEtude Then
        If Len(chkNomEtude) > 0 Then
        SQL = SQL & "And Patients!NomEtude = '" & Me.cmbRechNomEtude & "' "
        End If
    End If
     
    If Not Me.chkNomInvestigateur Then
        If Len(chkNomInvestigateur) > 0 Then
        SQL = SQL & "And Patients!NomInvestigateur = '" & Me.cmbRechNomInvestigateur & "' "
        End If
    End If
     
     
    If Not Me.chkTYPEDEPATHOLOGIE Then
        If Len(chkTYPEDEPATHOLOGIE) > 0 Then
        SQL = SQL & "And Patients!TYPEDEPATHOLOGIE = '" & Me.cmbRechTYPEDEPATHOLOGIE & "' "
        End If
    End If
     
    If Me.chkDC Then
       SQL = SQL & "ORDER BY [PATIENTS]![DC] ASC;"
    End If
     
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
    SQL = SQL & SQLOrder ";"
    SQL = SQL & ";"
     
    Me.lblStats.Caption = DCount("*", "Patients", SQLWhere) & " / " & DCount("*", "Patients")
    Me.lstResults.RowSource = SQL
    Me.lstResults.Requery
     
    Dim Nbtotal, Resul As Integer
     
    Nbtotal = DCount("*", "Patients")
    Resul = DCount("*", "Patients", SQLWhere)
    Me.Texte50 = (Resul / Nbtotal) * 100
    End Sub

  6. #6
    Expert éminent
    Avatar de cafeine
    Inscrit en
    Juin 2002
    Messages
    3 904
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 3 904
    Points : 6 781
    Points
    6 781
    Par défaut
    Paul,

    tu n'as pas bien lu mon message (ça fait deux fois .. hum hum :p ), ce qui est dans ton code ne correspond pas ... comment dès lors savoir si ma suggestion fonctionne ?

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    vraiment désole j'ai du copier/coller en cours de "bidouillage"...

    voici le code actuel
    Pas de debogage demandé mais pas de résultats correct.
    lorsque je décoche la chkDC plus de listing et plus de choix

    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
    Option Compare Database
    Option Explicit
     
     
    Private Sub chkDC_Click()
       RefreshQuery
    End Sub
     
    ' [cafeine] j'ai fait des coupes....
     
    If Not Me.chkTYPEDEPATHOLOGIE Then
        If Len(chkTYPEDEPATHOLOGIE) > 0 Then
        SQL = SQL & "And Patients!TYPEDEPATHOLOGIE = '" & Me.cmbRechTYPEDEPATHOLOGIE & "' "
        End If
    End If
     
    If Me.chkDC Then
       SQLOrder = " ORDER BY [PATIENTS]![DC]  ASC"
    End If
     
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
    SQL = SQL & SQLOrder & ";"
     
    Me.lblStats.Caption = DCount("*", "Patients", SQLWhere) & " / " & DCount("*", "Patients")
    Me.lstResults.RowSource = SQL
    Me.lstResults.Requery
     
    Dim Nbtotal, Resul As Integer
     
    Nbtotal = DCount("*", "Patients")
    Resul = DCount("*", "Patients", SQLWhere)
    Me.Texte50 = (Resul / Nbtotal) * 100
    End Sub

  8. #8
    Expert éminent
    Avatar de cafeine
    Inscrit en
    Juin 2002
    Messages
    3 904
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 3 904
    Points : 6 781
    Points
    6 781
    Par défaut
    j'ai édité ton message pour éviter de remettre encore une palanquée de lignes de code (assez de pub pour mon tuto ) ...
    dis nous si ça passe mieux maintenant ...

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    non désolé pas de résulat mais pas de message d'erreur...

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    du nouveau,
    il semblerait que lorsqu'je decoche la case chkDC cela trie en premier les enregistrements correspondants au critere...(en ce sens cela pourrait marcher)
    Mais l'afffichage (lstResults) se fait en totalité en affichant en premier les patients correspondants au critère.
    et le compteur (lblStats) ne compte pas le résultat du critère

  11. #11
    Expert éminent
    Avatar de cafeine
    Inscrit en
    Juin 2002
    Messages
    3 904
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 3 904
    Points : 6 781
    Points
    6 781
    Par défaut
    est-ce que ça marchait avant l'ajout de cette instruction de tri ... car je n'ai pas tout relu ...

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    bonjour,
    oui mon form de recherche multi-critères marche parfaitement

    en fait et en approfondissant mon objectif d'utilisation,
    je crois bien que j'ai fais une erreur de formulation dans ma demande
    Ce qui me fait besoin, ce n'est pas un tri, mais un filtrage.
    cad que seuls ne sortent les résultats qui correspondent à "cmbRechNomInvestigateur" et/ou "cmbRechNomEtude" et/ou "cmbRechTYPEDEPATHOLOGIE" et/ou"chkDC"
    afin de n'avoir en affichage et en compteur que les resultats issus des conditions..

  13. #13
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    binjour,
    si quelqu'un pouvait m'aider à terminer.....
    Merci par avance

  14. #14
    Membre éprouvé
    Avatar de keita
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    881
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations forums :
    Inscription : Novembre 2002
    Messages : 881
    Points : 1 121
    Points
    1 121
    Par défaut
    Paul87 a écrit:
    ...je crois bien que j'ai fais une erreur de formulation dans ma demande
    tu veux dire qu'en fait ce n'est pas une recherche multi-criteres qu'il te faut?
    @+

  15. #15
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    BONJOUR,
    si si c'est un form multi-crit....le meme que le tuto de cafeine....
    qui est en place actuellement et qui fonctionne à la perfection......(grace au forum)
    seulement je souhaite lui rajouter un critère non pas basé sur des chk ou cmbox....mais seulement basé sur chk (pour filtrer en plus sur un champ oui/non)
    les propositions plus haut fontionnent.....Ce qui me fait besoin,
    ce n'est pas un tri, mais un filtrage.
    cad que seuls ne sortent les résultats qui correspondent à "cmbRechNomInvestigateur" et/ou "cmbRechNomEtude" et/ou "cmbRechTYPEDEPATHOLOGIE" et/ou"chkDC"
    afin de n'avoir en affichage et en compteur que les resultats issus des conditions..
    et là je plante
    MERCI

  16. #16
    Membre éprouvé
    Avatar de keita
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    881
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations forums :
    Inscription : Novembre 2002
    Messages : 881
    Points : 1 121
    Points
    1 121
    Par défaut
    Essai ceci:
    partie de ton code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    If Me.chkDC Then 
       SQLOrder = " ORDER BY [PATIENTS]![DC]  ASC" 
    End If
    Cafeine t'a dit de mettre ceci à la place:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    If Me.chkTri Then 
       SQL = SQL & "ORDER BY [MaTable]![MonChampTrié] ASC;" 
    End If
    MonChampTrié est le nom du champ sur lequel ton filtre doit s'appliquer; car [PATIENTS]![DC] n'est pas un champ de ta table.
    je reste à l'ecoute.
    @+

  17. #17
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    ça ne marche toujours pas...
    mais "PATIENTS" et le nom de la table et "DC" est le nom du champ(oui/non) sur lequel je veux filtrer
    Ci-joint mon code ....parcque là suis largué

    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
    Private Sub chkDC_Click()
       RefreshQuery
    End Sub
     
    Private Sub chkNomEtude_Click()
     
    If Me.chkNomEtude Then
        Me.cmbRechNomEtude.Visible = False
    Else
        Me.cmbRechNomEtude.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
    Private Sub chkNomInvestigateur_Click()
     
    If Me.chkNomInvestigateur Then
        Me.cmbRechNomInvestigateur.Visible = False
    Else
        Me.cmbRechNomInvestigateur.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
     
    Private Sub chkTYPEDEPATHOLOGIE_Click()
     
    If Me.chkTYPEDEPATHOLOGIE Then
        Me.cmbRechTYPEDEPATHOLOGIE.Visible = False
    Else
        Me.cmbRechTYPEDEPATHOLOGIE.Visible = True
    End If
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechNomEtude_BeforeUpdate(Cancel As Integer)
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechNomInvestigateur_BeforeUpdate(Cancel As Integer)
     
    RefreshQuery
     
    End Sub
     
    Private Sub cmbRechTYPEDEPATHOLOGIE_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 "txt"
                ctl.Visible = False
                ctl.Value = ""
     
            Case "cmb"
                ctl.Visible = False
     
        End Select
    Next ctl
     
    Me.lstResults.RowSource = "SELECT Reclin, NOM,PRENOM, NOMETUDE, NOMINVESTIGATEUR, TYPEDEPATHOLOGIE, FROM Patients;"
    Me.lstResults.Requery
     
    End Sub
    Private Sub RefreshQuery()
     
    Dim SQL As String
    Dim SQLWhere As String
     
    SQL = "SELECT Reclin, NOM, PRENOM, NOMETUDE, NOMINVESTIGATEUR, TYPEDEPATHOLOGIE, FROM Patients Where Patients!Reclin <> 0 "
     
     
     
    If Not Me.chkNomEtude Then
        If Len(chkNomEtude) > 0 Then
        SQL = SQL & "And Patients!NomEtude = '" & Me.cmbRechNomEtude & "' "
        End If
    End If
     
    If Not Me.chkNomInvestigateur Then
        If Len(chkNomInvestigateur) > 0 Then
        SQL = SQL & "And Patients!NomInvestigateur = '" & Me.cmbRechNomInvestigateur & "' "
        End If
    End If
     
     
    If Not Me.chkTYPEDEPATHOLOGIE Then
        If Len(chkTYPEDEPATHOLOGIE) > 0 Then
        SQL = SQL & "And Patients!TYPEDEPATHOLOGIE = '" & Me.cmbRechTYPEDEPATHOLOGIE & "' "
        End If
    End If
     
    If Me.chkDC Then
       SQLOrder = " ORDER BY [PATIENTS]![DC]  ASC"
    End If
     
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
    SQL = SQL & SQLOrder & ";"
     
    Me.lblStats.Caption = DCount("*", "Patients", SQLWhere) & " / " & DCount("*", "Patients")
    Me.lstResults.RowSource = SQL
    Me.lstResults.Requery
     
     
    Dim Nbtotal, Resul As Integer
     
    Nbtotal = DCount("*", "Patients")
    Resul = DCount("*", "Patients", SQLWhere)
    Me.Texte50 = (Resul / Nbtotal) * 100
    End Sub

  18. #18
    Expert éminent sénior

    Avatar de Tofalu
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2004
    Messages
    9 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Octobre 2004
    Messages : 9 501
    Points : 32 311
    Points
    32 311
    Par défaut
    Tu as essayé de debuguer ? Que vaut SQL à la fin ?

  19. #19
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    388
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 388
    Points : 72
    Points
    72
    Par défaut
    Bonjour,
    pas de d'erreur ou de code ou message de debog....
    mais l'affichage TRIE et ne FILTRE pas cad que dans la lstResults j'ai l'affichage complet des enregistrements avec en haut de liste (ASC) ceux qui correspondent a chkDC lorsqu'elle est cochée et je ne veux que l'affichage et le compteur lblStats de ceux qui correspondent à toutes les conditions...
    Merci

  20. #20
    Membre éprouvé
    Avatar de keita
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    881
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations forums :
    Inscription : Novembre 2002
    Messages : 881
    Points : 1 121
    Points
    1 121
    Par défaut
    Je comprends mieux ton pb;tu ne peux pas faire ORDER BY sur un champ oui/non.tu peus retourner ceux qui sont oui ou l'inverse; donc essai ça:
    partie de ton code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    If Me.chkDC Then 
       SQLOrder = " ORDER BY [PATIENTS]![DC]  ASC" 
    End If 
     
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1)) 
    SQL = SQL & SQLOrder & ";"
    essai ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    If Me.chkDC Then 
       SQL = SQL & "And Patients![DC] " & ";" 
    End If 
     
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
    c'est ici qu'il faut chercher.
    @+

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 4 1234 DernièreDernière

Discussions similaires

  1. Recherche multi-critères
    Par AzAiEz dans le forum Access
    Réponses: 4
    Dernier message: 13/01/2006, 17h05
  2. [MySQL] Recherche multi-critères ou un seul
    Par jack1234 dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 14/12/2005, 08h56
  3. problème SQL avec le tutoriel recherche multi critère
    Par qbihlmaier dans le forum Requêtes et SQL.
    Réponses: 1
    Dernier message: 05/12/2005, 19h33
  4. problème avec résultat de recherche multi-critères
    Par audrey_desgres dans le forum Access
    Réponses: 2
    Dernier message: 23/06/2005, 11h00
  5. Procédure stockée: recherche multi-critères
    Par biroule dans le forum MS SQL Server
    Réponses: 11
    Dernier message: 01/09/2004, 16h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo