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
| Public Sub ListviewFiltree()
Dim LV As MSComctlLib.ListView
Dim li As ListItem
Dim FiltreSQL As TempVars
Dim FiltreRegistres As TempVars
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Set LV = Me.ListView.Object
'Set LV.ColumnHeaderIcons = Me.ImageList1.Object
With LV
.View = lvwReport
.ListItems.Clear
.GridLines = True
.Appearance = cc3D
.Font.Name = "arial"
.Font.Size = 8
.AllowColumnReorder = True
.FullRowSelect = True
.MultiSelect = True
.LabelEdit = False
End With
With LV.ColumnHeaders
.Clear
Select Case Me.ChoixFiltre
Case 1
.Add , , "IDMairie", 0, lvwColumnLeft
Case 2
.Add , , "IDcommune", 0, lvwColumnLeft
End Select
.Add , , "Fiche", 1000, lvwColumnLeft
.Add , , "Commune", 4000, lvwColumnLeft
.Add , , "INSEE", 800, lvwColumnRight
.Add , , "C.P.", 800, lvwColumnRight
.Add , , "EPCI", 6000
.Add , , "Département", 3000
.Add , , "Commercial", 4000
End With
'filtrage suivant choix
Dim sql As String
Dim sql1 As String
Dim sql2 As String
sql1 = "select idmairie,Fiche,Commune,CodeInseecommune as [INSEE],codepostalcommune as [CP],Siren,EPCI,Département,Préfecture,Région,Commercial,datecreation from rqmairies"
sql2 = "select idcommune,Fiche,Commune,CodeInseecommune as [INSEE],codepostalcommune as [CP],Siren,EPCI,Département,Préfecture,Région,Commercial from rqcommunes"
Select Case Me.ChoixFiltre
Case 1 And Me.OptChoixMode = 1
sql = sql1 + " where [Département]='" & Apos(Me.CboRecherche) & "'"
Case 1 And Me.OptChoixMode = 2
sql = sql2 + " where [Département]='" & Apos(Me.CboRecherche) & "'"
Case 2 And Me.OptChoixMode = 1
sql = sql1 + " where epci='" & Apos(Me.CboRecherche) & "'order by commune"
Case 2 And Me.OptChoixMode = 2
sql = sql2 + " where epci='" & Apos(Me.CboRecherche) & "'order by commune"
Case 3 And Me.OptChoixMode = 1
sql = sql1 + " where commune='" & Apos(Me.CboRecherche) & "'order by commune"
Case 3 And Me.OptChoixMode = 2
sql = sql2 + " where commune='" & Apos(Me.CboRecherche) & "'order by commune"
Case 4 And Me.OptChoixMode = 1
sql = sql1 + " where codeinseecommune='" & Me.CboRecherche & "'"
Case 4 And Me.OptChoixMode = 2
sql = sql2 + " where codeinseecommune='" & Me.CboRecherche & "'"
Case 5 And Me.OptChoixMode = 1
sql = sql1 + " where codepostalcommune='" & Me.CboRecherche & "'"
Case 5 And Me.OptChoixMode = 2
sql = sql2 + " where codepostalcommune='" & Me.CboRecherche & "'"
Case 6 And Me.OptChoixMode = 1
sql = sql1 + " where région='" & Apos(Me.CboRecherche) & "'order by commune"
Case 6 And Me.OptChoixMode = 2
sql = sql2 + " where région='" & Apos(Me.CboRecherche) & "'order by commune"
Case 7 And Me.OptChoixMode = 1
sql = sql1 + " where préfecture='" & Apos(Me.CboRecherche) & "'order by commune"
Case 7 And Me.OptChoixMode = 2
sql = sql2 + " where préfecture='" & Apos(Me.CboRecherche) & "'order by commune"
Case 8 And Me.OptChoixMode = 1
sql = sql1 + " where idcommune=" & Me.CboRecherche & " order by commune"
Case 8 And Me.OptChoixMode = 2
sql = sql2 + " where idcommune=" & Me.CboRecherche & " order by commune"
Case 9 And Me.OptChoixMode = 1
sql = sql1 + " where idcommercial='" & Me.CboRecherche.Column(0) & "'"
Case 9 And Me.OptChoixMode = 2
sql = sql2 + " where idcommercial='" & Me.CboRecherche.Column(0) & "'"
Case 10 And Me.OptChoixMode = 1
sql = sql1 + " where datecreation=" & "#" & Format(Me.CboRecherche.Column(0), "mm/dd/yyyy hh:nn:ss") & "#"
End Select
Debug.Print sql
Set rs = CurrentDb.OpenRecordset(sql)
'Set rs2 = CurrentDb.OpenRecordset("select * from rqmairies where idmairie='" & rs!IDMairie & "'")
TempVars!FiltreSQL = sql
VoirListingCommunes
'rs.MoveFirst
Do Until rs.EOF
' Add items and subitems to list control.
Select Case Me.OptChoixMode
Case 1
Set li = LV.ListItems.Add(, , rs!IDMairie)
Case 2
Set li = LV.ListItems.Add(, , rs!IDCommune)
End Select
li.ListSubItems.Add , , Nz(rs!fiche)
li.ListSubItems.Add , , Nz(rs!Commune)
li.ListSubItems.Add , , Nz(rs!Insee)
li.ListSubItems.Add , , Nz(rs!cp)
li.ListSubItems.Add , , Nz(rs!EPCI)
li.ListSubItems.Add , , Nz(rs!Département)
li.ListSubItems.Add , , Nz(rs!Commercial)
li.ListSubItems(1).ForeColor = vbBlue
li.ListSubItems(2).ForeColor = RGB(100, 0, 100)
li.ListSubItems(2).Bold = True
li.ListSubItems(5).ForeColor = RGB(0, 50, 0)
li.ListSubItems(5).Bold = True
li.ListSubItems(6).Bold = True
rs.MoveNext
Loop
Set LV = Nothing
rs.Close
Me.OptToutSelectionner.Enabled = True
End Sub |
Partager