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
| Private Sub btSelection_Click()
Dim ctlReg As Control
Dim ctlDep As Control
Dim varItm As Variant
Dim stSQL As String
On Error GoTo hd_err
' Déclaration des objets liste à sélection multiple
Set ctlReg = Me.RegionFiltre
Set ctlDep = Me.DepartementFiltre
' Si au moins une sélection effectuée
If ctlReg.ItemsSelected.Count + ctlDep.ItemsSelected.Count > 0 Then
stSQL = "SELECT * FROM GeoCommuneReq WHERE "
End If
' Lecture de la sélection Régions
If ctlReg.ItemsSelected.Count > 0 Then
stSQL = stSQL & "([N°Region] In ("
For Each varItm In ctlReg.ItemsSelected
stSQL = stSQL & ctlReg.ItemData(varItm) & ","
Next varItm
' Pour enlever la dernière virgule
stSQL = Left(stSQL, Len(stSQL) - 1) & "))"
End If
' Départements
If ctlDep.ItemsSelected.Count > 0 Then
' Si au moins une région est sélectionnée
If ctlReg.ItemsSelected.Count > 0 Then
stSQL = stSQL & " OR "
End If
stSQL = stSQL & "([N°Dept] In ("
' Lecture de la sélection des département
For Each varItm In ctlDep.ItemsSelected
stSQL = stSQL & "'" & ctlDep.ItemData(varItm) & "',"
Next varItm
' Pour enlever la dernière virgule
stSQL = Left(stSQL, Len(stSQL) - 1) & "))"
End If
' Fin d'instruction SQL et chargement des données sélectionnées
If ctlReg.ItemsSelected.Count + ctlDep.ItemsSelected.Count > 0 Then
stSQL = stSQL & ";"
Me.RecordSource = stSQL
End If
Exit Sub
hd_err:
MsgBox "Erreur :" & Err.Number & " - " & Err.Description
Resume Next
End Sub |
Partager