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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
| Option Explicit
Dim REGION As String
Dim DEPARTEMENT As String
Dim CANTON As String
Dim EPCI As String
Dim AGGLO As String
Dim ARR As String
Dim COMMUNE As String
Dim IRIS As String
'*******************************************************
' Procédure appelée lors d'un double clic sur SELECTION
'*******************************************************
Private Sub AJOUTER_DblClick(Cancel As Integer)
AJOUTER
End Sub
'*******************************************************
' Procédure appelée lors d'un clic sur le bouton "ajouter"
' Cette procédure va, suivant le type de l'échelle sélectionner et
' effectuer une requete pour rassembler les informations
' sur cette dernière
'
' Une erreur est levée en cas de violation des contraintes d'utilisation
' (exemple : pluseurs cases cochées en même temps)
'*******************************************************
Private Sub AJOUTER_Click()
Dim resultatReq As Recordset 'Résultat Requête
Dim TYPE_ECHELLE As String 'champs qui renseigne le type de l'enregistrement (exp: REG, DEP ...)
'Vérifier conditions
If VERIFIER_CONDITIONS = False Then
MsgBox ("Veuillez vérifier que vous avez sélectionné ou coché une seule echelle")
Exit Sub
End If
'récupérer les valeurs des LISTE_
VALEUR_LISTES
If coche_R Then 'Ajouter toutes les regions
TYPE_ECHELLE = "REG"
If REGION <> "" Or DEPARTEMENT <> "" Or CANTON <> "" Or EPCI <> "" Or AGGLO <> "" Or ARR <> "" Or COMMUNE <> "" Or IRIS <> "" Then
MsgBox ("Impossible d'executer")
Exit Sub
End If
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT REG as CODE,LIBELREG as LIBEL FROM COMMUNE")
ElseIf coche_D Then
TYPE_ECHELLE = "DEP"
If DEPARTEMENT <> "" Or CANTON <> "" Or EPCI <> "" Or AGGLO <> "" Or ARR <> "" Or COMMUNE <> "" Or IRIS <> "" Then
MsgBox ("Impossible d'executer")
Exit Sub
End If
If REGION <> "" Then 'si une région est selectionnée
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT DEP as CODE,LIBELDEP as LIBEL FROM COMMUNE WHERE LIBELREG='" & REGION & "'")
Else 'ajouter toutes les dep
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT DEP as CODE,LIBELDEP as LIBEL FROM COMMUNE")
End If
ElseIf COCHE_C Then
TYPE_ECHELLE = "CANTON"
If CANTON <> "" Or EPCI <> "" Or AGGLO <> "" Or ARR <> "" Or COMMUNE <> "" Or IRIS <> "" Then
MsgBox ("Impossible d'executer")
Exit Sub
End If
If DEPARTEMENT <> "" Then 'Ajouter tous les cantons de DEPARTEMENT
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CV as CODE,LIBELCV as LIBEL FROM COMMUNE WHERE LIBELDEP='" & DEPARTEMENT & "' OR DEP='" & DEPARTEMENT & "'")
ElseIf REGION <> "" Then 'Ajouter tous les cantons de REGION
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CV as CODE,LIBELCV as LIBEL FROM COMMUNE WHERE LIBELREG='" & REGION & "'")
Else 'DEPARTEMENT et REGION sont vides, alors on ajoute TOUS les cantons
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CV as CODE,LIBELCV as LIBEL FROM COMMUNE")
End If
ElseIf COCHE_EPCI Then
TYPE_ECHELLE = "EPCI"
If EPCI <> "" Or AGGLO <> "" Or ARR <> "" Or COMMUNE <> "" Or IRIS <> "" Then
MsgBox ("Impossible d'executer")
Exit Sub
End If
If CANTON <> "" Then 'Ajouter tous les EPCI de Canton
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT EPCI as CODE,LIBELEPCI as LIBEL FROM COMMUNE WHERE LIBELCV='" & CANTON & "' OR CV='" & CANTON & "'")
ElseIf DEPARTEMENT <> "" Then 'Ajouter tous les EPCI de DEPARTEMENT
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT EPCI as CODE,LIBELEPCI as LIBEL FROM COMMUNE WHERE LIBELDEP='" & DEPARTEMENT & "' OR DEP='" & DEPARTEMENT & "'")
ElseIf REGION <> "" Then 'Ajouter tous les EPCI de REGION
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT EPCI as CODE,LIBELEPCI as LIBEL FROM COMMUNE WHERE LIBELREG='" & REGION & "'")
Else 'CANTON,DEPARTEMENT,REGION sont vides, alors on ajoute TOUS les EPCI
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT EPCI as CODE,LIBELEPCI as LIBEL FROM COMMUNE")
End If
ElseIf COCHE_AG Then
TYPE_ECHELLE = "AGGLO"
If AGGLO <> "" Or ARR <> "" Or COMMUNE <> "" Or IRIS <> "" Then
MsgBox ("Impossible d'executer")
Exit Sub
End If
If EPCI <> "" Then 'Ajouter toutes les AGG de EPCI
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT UU1999 as CODE,LIBELUU1999 as LIBEL FROM COMMUNE WHERE LIBELEPCI='" & EPCI & "' OR EPCI='" & EPCI & "'")
ElseIf CANTON <> "" Then 'Ajouter toutes les AGG de Canton
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT UU1999 as CODE,LIBELUU1999 as LIBEL FROM COMMUNE WHERE LIBELCV='" & CANTON & "' OR CV='" & CANTON & "'")
ElseIf DEPARTEMENT <> "" Then 'Ajouter tous les AGG de DEPARTEMENT
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT UU1999 as CODE,LIBELUU1999 as LIBEL FROM COMMUNE WHERE LIBELDEP='" & DEPARTEMENT & "' OR DEP='" & DEPARTEMENT & "'")
ElseIf REGION <> "" Then 'Ajouter toutes les AGG de REGION
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT UU1999 as CODE,LIBELUU1999 as LIBEL FROM COMMUNE WHERE LIBELREG='" & REGION & "'")
Else 'EPCI,CANTON,DEPARTEMENT,REGION sont vides, alors on ajoute TOUTES les AGG
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT UU1999 as CODE,LIBELUU1999 as LIBEL FROM COMMUNE")
End If
ElseIf COCHE_AR Then
TYPE_ECHELLE = "ARR"
If REGION = "Provence-Alpes-Côte d'Azur" Or REGION = "93" Or REGION = "Rhône-Alpes" Or REGION = "83" Or REGION = "Ile-de-France" Or REGION = "11" Then
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM ARRONDISSEMENT WHERE LIBELREG='" & COMMUNE & "' OR REG='" & COMMUNE & "'")
ElseIf DEPARTEMENT = "Bouche-du-Rhône" Or DEPARTEMENT = "13" Or DEPARTEMENT = "Rhône" Or DEPARTEMENT = "69" Or DEPARTEMENT = "Paris" Or DEPARTEMENT = "75" Then
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM ARRONDISSEMENT WHERE LIBELDEP='" & COMMUNE & "' OR DEP='" & COMMUNE & "'")
ElseIf CANTON = "Marseille" Or CANTON = "1399" Or CANTON = "LYON" Or CANTON = "6999" Or CANTON = "Paris" Or CANTON = "7599" Then
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM ARRONDISSEMENT WHERE LIBELCV='" & ARR & "' OR LIBELCV='" & COMMUNE & "'")
ElseIf ARR = "Marseille" Or ARR = "Lyon" Or ARR = "Paris" Then
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM ARRONDISSEMENT WHERE LIBELCV='" & ARR & "'")
ElseIf AGGLO = "" And EPCI = "" And CANTON = "" And DEPARTEMENT = "" And REGION = "" And ARR = "" Then
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM ARRONDISSEMENT")
'///////////////////////////////////////////////////////////////////////////////////////////////
'SI ON CREE UNE NOUVEL ARRONDISSEMENT, IL FAUT ALORS AJOUTER UN "ELSE IF"
'///////////////////////////////////////////////////////////////////////////////////////////////
Else
MsgBox ("Impossible d'executer")
Exit Sub
End If
ElseIf COCHE_COM Then
TYPE_ECHELLE = "COM"
If COMMUNE <> "" Or IRIS <> "" Then
MsgBox ("Impossible d'executer")
Exit Sub
End If
If ARR <> "" Then 'Ajouter toutes les COM de ARR
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM ARRONDISSEMENT WHERE LIBGEO='" & ARR & "' OR CODEGEO='" & ARR & "'")
ElseIf AGGLO <> "" Then 'Ajouter toutes les COM de AGG
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM COMMUNE WHERE LIBELUU1999='" & AGGLO & "' OR UU1999='" & AGGLO & "'")
ElseIf EPCI <> "" Then 'Ajouter toutes les COM de EPCI
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM COMMUNE WHERE LIBELEPCI='" & EPCI & "' OR EPCI='" & EPCI & "'")
ElseIf CANTON <> "" Then 'Ajouter toutes les COM de Canton
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM COMMUNE WHERE LIBELCV='" & CANTON & "' OR CV='" & CANTON & "'")
ElseIf DEPARTEMENT <> "" Then 'Ajouter toutes les COM de DEPARTEMENT
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM COMMUNE WHERE LIBELDEP='" & DEPARTEMENT & "' OR DEP='" & DEPARTEMENT & "'")
ElseIf REGION <> "" Then 'Ajouter toutes les COM de REGION
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM COMMUNE WHERE LIBELREG='" & REGION & "'")
Else 'ARR,AGG,EPCI,CANTON,DEPARTEMENT,REGION sont vides, alors on ajoute TOUTES les COMMUNE
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM COMMUNE")
End If
ElseIf COCHE_IRIS Then
TYPE_ECHELLE = "IRIS"
If IRIS <> "" Then
MsgBox ("Impossible d'executer")
Exit Sub
End If
If COMMUNE <> "" Then 'Ajouter tous les IRIS de COM
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS WHERE LIBGEO='" & COMMUNE & "' OR CODGEO='" & COMMUNE & "'")
ElseIf ARR <> "" Then 'Ajouter tous les IRIS de ARR
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS WHERE LIBGEO='" & ARR & "' OR CODGEO='" & ARR & "'")
ElseIf AGGLO <> "" Then 'Ajouter tous les IRIS de AGG
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM COMMUNE WHERE LIBELUU1999='" & AGGLO & "' OR UU1999='" & AGGLO & "'")
ElseIf EPCI <> "" Then 'Ajouter tous les IRIS de EPCI
'Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS WHERE LIBELEPCI='" & EPCI & "' OR EPCI='" & EPCI & "'")
MsgBox ("Vous ne pouvez pas faire de filtre à partir d'un EPCI")
ElseIf CANTON <> "" Then 'Ajouter tous les IRIS de Canton
'Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS WHERE LIBELCV='" & CANTON & "' OR CV='" & CANTON & "'")
MsgBox ("Vous ne pouvez pas faire de filtre à partir d'un CANTON")
ElseIf DEPARTEMENT <> "" Then 'Ajouter tous les IRIS de DEPARTEMENT
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS WHERE LIBELDEP='" & DEPARTEMENT & "' OR DEP='" & DEPARTEMENT & "'")
ElseIf REGION <> "" Then 'Ajouter tous les IRIS de REGION
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS WHERE LIBELREG='" & REGION & "'")
Else 'COMMUNE,ARR,AGG,EPCI,CANTON,DEPARTEMENT,REGION sont vides, alors on ajoute TOUS les IRIS
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS")
End If
Else
'Aucune case cochée
'alors on recherche dans les champs LISTE_**
If REGION <> "" Then 'ajouter la region souhaitée
TYPE_ECHELLE = "REG"
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT REG as CODE,LIBELREG as LIBEL FROM COMMUNE WHERE LIBELREG='" & REGION & "'")
ElseIf DEPARTEMENT <> "" Then 'ajouter le département souhaité
TYPE_ECHELLE = "DEP"
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT DEP as CODE,LIBELDEP as LIBEL FROM COMMUNE WHERE LIBELDEP='" & DEPARTEMENT & "' OR DEP='" & DEPARTEMENT & "'")
ElseIf CANTON <> "" Then 'ajouter le canton souhaité
TYPE_ECHELLE = "CANTON"
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CV as CODE,LIBELCV as LIBEL FROM COMMUNE WHERE LIBELCV='" & CANTON & "' OR CV='" & CANTON & "'")
ElseIf EPCI <> "" Then 'ajouter l'EPCI souhaité
TYPE_ECHELLE = "EPCI"
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT EPCI as CODE,LIBELEPCI as LIBEL FROM COMMUNE WHERE LIBELEPCI='" & EPCI & "' OR EPCI='" & EPCI & "'")
ElseIf AGGLO <> "" Then 'ajouter l'Agglo souhaitée
TYPE_ECHELLE = "AGGLO"
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT UU1999 as CODE,LIBELUU1999 as LIBEL FROM COMMUNE WHERE LIBELUU1999='" & AGGLO & "' OR UU1999='" & AGGLO & "'")
ElseIf ARR <> "" Then 'ajouter l'arr souhaitée
TYPE_ECHELLE = "ARR"
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT CODGEO as CODE,LIBGEO as LIBEL FROM ARRONDISSEMENT WHERE LIBGEO='" & ARR & "' OR CODGEO='" & ARR & "'")
ElseIf COMMUNE <> "" Then 'ajouter la commune souhaitée
TYPE_ECHELLE = "COM"
Set resultatReq = CurrentDb.OpenRecordset("SELECT CODGEO as CODE,LIBGEO as LIBEL FROM COMMUNE WHERE LIBGEO='" & COMMUNE & "' OR CODGEO='" & COMMUNE & "'")
ElseIf IRIS <> "" Then
TYPE_ECHELLE = "IRIS"
Set resultatReq = CurrentDb.OpenRecordset("SELECT DISTINCT IRIS as CODE,LIBELIRIS as LIBEL FROM IRIS WHERE LIBELIRIS='" & IRIS & "' OR IRIS='" & IRIS & "'")
End If
End If
'Ajout des résultats dans la liste
resultatReq.MoveFirst
While Not resultatReq.EOF
SELECTION.AddItem resultatReq!CODE & ";" & resultatReq!LIBEL & ";" & TYPE_ECHELLE 'ajout de la région
resultatReq.MoveNext
Wend
VIDER_ECHELLES
MsgBox SELECTION.ListCount
End Sub |
Partager