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
| Private Function TreeView()
'Je définis mes variables
Dim db As dao.Database
Dim rst As dao.Recordset
Dim NodCurrent As Node, nodRoot As Node
Dim objTree As TreeView
Dim strSql As String
Dim strText As String
Dim ValWhere As String
Dim ValHaving As String
Set db = CurrentDb
'Création de la référence à l'objet Treeview
Set objTree = Me.TrwMenu.Object
TrwMenu.Nodes.Clear
'Je définis le titre et la couleur du noeud en cours
Set NodCurrent = objTree.Nodes.Add(, , MyKey1, "Résultat de Recherche")
NodCurrent.ForeColor = RGB(128, 0, 0)
'Ici, simplifie au maximum ta requête. N'utilise que ce que tu as besoin dans le Treeview
'Affichage des Régions bues
strSql = "SELECT rqy_Historique.Pays, rqy_Historique.Region, [rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region] AS PaysEtRegion FROM rqy_Historique WHERE ((([rqy_Historique]![Appellation]" & " & " & "[rqy_Historique]![Type]) Is Not Null)"
If Not IsNull(Me.TxtAlphabet) Then
ValWhere = " AND ((rqy_Historique.Appellation) like '*" & Me.TxtAlphabet & "*' )"
End If
If Not IsNull(Me.lstType) Then
ValWhere = ValWhere & " AND ((rqy_Historique.Type) =" & Chr(34) & Me.lstType & Chr(34) & ")"
End If
If Not IsNull(Me.lstAnnee) Then
ValWhere = ValWhere & " AND ((rqy_Historique.Annee)=" & Chr(34) & Me.lstAnnee & Chr(34) & ")"
End If
strSql = strSql & ValWhere & ") GROUP BY rqy_Historique.Pays, rqy_Historique.Region, [rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region] HAVING ((([rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region])Is Not Null)"
If Not IsNull(Me.lstPays) Then
ValHaving = " AND ((rqy_Historique.Pays)=" & Chr(34) & Me.lstPays & Chr(34) & ")"
End If
If Not IsNull(Me.lstRegion) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Region)=" & Chr(34) & Me.lstRegion & Chr(34) & ")"
End If
strSql = strSql & ValHaving & ") ORDER BY rqy_Historique.Pays;"
Set rst = db.OpenRecordset(strSql)
Do Until rst.EOF
'Texte à afficher dans le Treeview. Tu peux concaténer tous les champs que tu veux...
strText = rst!Pays & " - " & rst!Region
'J'ajoute un noeud...
Set NodCurrent = objTree.Nodes.Add(MyKey1, tvwChild, MyKey2 & rst![Region], strText, 2)
NodCurrent.ForeColor = RGB(128, 0, 0)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
'Affichage des Apellations bues
strSql = "SELECT rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Region, rqy_Historique.NumAppellationComplete, [rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region] AS PaysEtRegion FROM rqy_Historique WHERE ((([rqy_Historique]![Appellation]" & " & " & "[rqy_Historique]![Type]) Is Not Null)"
If Not IsNull(Me.lstType) Then
ValWhere = " AND ((rqy_Historique.Type) =" & Chr(34) & Me.lstType & Chr(34) & ")"
End If
If Not IsNull(Me.lstAnnee) Then
ValWhere = ValWhere & " AND ((rqy_Historique.Annee)=" & Chr(34) & Me.lstAnnee & Chr(34) & ")"
End If
strSql = strSql & ValWhere & ") GROUP BY rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Region, rqy_Historique.NumAppellationComplete, [rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region] HAVING ((([rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region])Is Not Null)"
If Not IsNull(Me.lstPays) Then
ValHaving = " AND ((rqy_Historique.Pays)=" & Chr(34) & Me.lstPays & Chr(34) & ")"
End If
If Not IsNull(Me.TxtAlphabet) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Appellation) like '*" & Me.TxtAlphabet & "*' )"
End If
If Not IsNull(Me.lstRegion) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Region)=" & Chr(34) & Me.lstRegion & Chr(34) & ")"
End If
strSql = strSql & ValHaving & ") ORDER BY rqy_Historique.Pays, rqy_Historique.Appellation;"
Set rst = db.OpenRecordset(strSql)
Do Until rst.EOF
'Texte à afficher dans le Treeview. Tu peux concaténer tous les champs que tu veux...
strText = rst!Appellation
'J'ajoute un noeud...
Set NodCurrent = objTree.Nodes.Add(MyKey2 & rst![Region], tvwChild, MyKey3 & rst![NumAppellationComplete], strText)
NodCurrent.ForeColor = RGB(128, 0, 0)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
'Affichage des millésimes bus
strSql = " SELECT rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Annee, rqy_Historique.Region, rqy_Historique.NumAppellationComplete, [tbl_AppellationComplete]![NumAppellationComplete] " & " & " & " [tbl_Cave]![Annee] AS NumAppellationCompleteEtAnnee, [rqy_Historique]![Pays] " & " & " & " [rqy_Historique]![Region] AS PaysEtRegion FROM rqy_Historique WHERE ((([rqy_Historique]![Appellation]" & " & " & "[rqy_Historique]![Type]) Is Not Null)"
If Not IsNull(Me.lstType) Then
ValWhere = " AND ((rqy_Historique.Type) =" & Chr(34) & Me.lstType & Chr(34) & ")"
End If
strSql = strSql & ValWhere & ") GROUP BY rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Annee, rqy_Historique.Region, rqy_Historique.NumAppellationComplete, [tbl_AppellationComplete]![NumAppellationComplete] " & " & " & " [tbl_Cave]![Annee], [rqy_Historique]![Pays] & [rqy_Historique]![Region] HAVING ((([rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region])Is Not Null)"
If Not IsNull(Me.lstPays) Then
ValHaving = " AND ((rqy_Historique.Pays)=" & Chr(34) & Me.lstPays & Chr(34) & ")"
End If
If Not IsNull(Me.TxtAlphabet) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Appellation) like '*" & Me.TxtAlphabet & "*' )"
End If
If Not IsNull(Me.lstAnnee) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Annee)=" & Chr(34) & Me.lstAnnee & Chr(34) & ")"
End If
If Not IsNull(Me.lstRegion) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Region)=" & Chr(34) & Me.lstRegion & Chr(34) & ")"
End If
strSql = strSql & ValHaving & ") ORDER BY rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Annee;"
Set rst = db.OpenRecordset(strSql)
Do Until rst.EOF
'Texte à afficher dans le Treeview. Tu peux concaténer tous les champs que tu veux...
strText = rst!Annee
'J'ajoute un noeud...
Set NodCurrent = objTree.Nodes.Add(MyKey3 & rst![NumAppellationComplete], tvwChild, MyKey4 & rst![NumAppellationCompleteEtAnnee], strText, 3)
NodCurrent.ForeColor = RGB(128, 0, 0)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
'Affichage des types par millésime
strSql = " SELECT rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Annee, rqy_Historique.Type, rqy_Historique.Region, rqy_Historique.NumAppellationComplete, [tbl_AppellationComplete]![NumAppellationComplete]" & " & " & "[tbl_Cave]![Annee] AS NumAppellationCompleteEtAnnee, ROUND(Avg(rqy_Degustation.Note),1) AS NoteDegust, Round([Tbl_Millesime].[Note],1) AS [Note], [tbl_AppellationComplete]![NumAppellationComplete]" & " & " & "[tbl_Cave]![Annee]" & " & " & "[tbl_Cave]![NumVin] AS NumAppellationCompleteEtAnneeEtNumVin, [rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region] AS PaysEtRegion " & _
"FROM (rqy_Historique LEFT JOIN tbl_Millesime ON (rqy_Historique.Annee = tbl_Millesime.Annee) AND (rqy_Historique.NumRegionEtSousRegion = tbl_Millesime.NumRegionEtSousRegion) AND (rqy_Historique.Type = tbl_Millesime.Type)) LEFT JOIN rqy_Degustation ON rqy_Historique.NumCave = rqy_Degustation.NumCave GROUP BY rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Annee, rqy_Historique.Type, rqy_Historique.Region, rqy_Historique.NumAppellationComplete, [tbl_AppellationComplete]![NumAppellationComplete]" & " & " & "[tbl_Cave]![Annee], Round([Tbl_Millesime].[Note],1), [tbl_AppellationComplete]![NumAppellationComplete]" & " & " & "[tbl_Cave]![Annee]" & " & " & "[tbl_Cave]![NumVin], [rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region] " & _
"HAVING ((([rqy_Historique]![Pays]" & " & " & "[rqy_Historique]![Region])Is Not Null)"
If Not IsNull(Me.lstPays) Then
ValHaving = " AND ((rqy_Historique.Pays) =" & Chr(34) & Me.lstPays & Chr(34) & ")"
End If
If Not IsNull(Me.TxtAlphabet) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Appellation) like '*" & Me.TxtAlphabet & "*' )"
End If
If Not IsNull(Me.lstAnnee) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Annee) =" & Chr(34) & Me.lstAnnee & Chr(34) & ")"
End If
If Not IsNull(Me.lstType) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Type) =" & Chr(34) & Me.lstType & Chr(34) & ")"
End If
If Not IsNull(Me.lstRegion) Then
ValHaving = ValHaving & " AND ((rqy_Historique.Region) =" & Chr(34) & Me.lstRegion & Chr(34) & ")"
End If
strSql = strSql & ValHaving & ") ORDER BY rqy_Historique.Pays, rqy_Historique.Appellation, rqy_Historique.Annee, rqy_Historique.Type;"
Set rst = db.OpenRecordset(strSql)
Do Until rst.EOF
'Texte à afficher dans le Treeview. Tu peux concaténer tous les champs que tu veux...
Dim NoteDegustNull As String
Dim NoteNull As String
If IsNull(rst!NoteDegust) Then
NoteDegustNull = "Abs"
Else
NoteDegustNull = rst!NoteDegust
End If
If IsNull(rst!note) Then
NoteNull = "Abs"
Else
NoteNull = rst!note
End If
strText = rst!Type & " - " & NoteDegustNull & " - " & NoteNull
'J'ajoute un noeud...
Set NodCurrent = objTree.Nodes.Add(MyKey4 & rst![NumAppellationCompleteEtAnnee], tvwChild, MyKey5 & rst![NumAppellationCompleteEtAnneeEtNumVin], strText, 1)
NodCurrent.ForeColor = RGB(128, 0, 0)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Me.TrwMenu.Nodes(1).Expanded = True
End Function
Private Sub ChercheGeneration(oNode As Node, intGeneration As Integer)
If Not oNode.Parent Is Nothing Then
intGeneration = intGeneration + 1
'Appeler la procédure pour le parent
ChercheGeneration oNode.Parent, intGeneration
End If
End Sub |
Partager