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
|
Option Compare Database
Option Explicit
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim NodX As node
Dim Menu As Control
Dim StrSql As String
Dim A As String
Dim B As String
Dim C As String
Dim I As Integer
Dim LaPosition As Integer
Public LaClé As String
Private Sub Form_Load()
On Error Resume Next
DoCmd.Maximize
Init_Menu
End Sub
Private Sub Init_Menu()
On Error Resume Next
Set Db = CurrentDb
Set Menu = Me.TreeView
With Menu.Nodes
'StrSql = "SELECT Clients.Société FROM (Catégories INNER JOIN Produits ON Catégories.[Code catégorie] = Produits.[Code catégorie]) INNER JOIN (Employés INNER JOIN ((Clients INNER JOIN Commandes ON Clients.[Code client] = Commandes.[Code client]) INNER JOIN [Détails commandes] ON Commandes.[N° commande] = [Détails commandes].[N° commande]) ON Employés.[N° employé] = Commandes.[N° employé]) ON Produits.[Réf produit] = [Détails commandes].[Réf produit] GROUP BY Clients.Société ORDER BY Clients.Société; "
StrSql = "SELECT category.categoryID, category.category FROM Category WHERE (((category.parent)=0));"
Set Rs = Db.OpenRecordset(StrSql)
Rs.MoveFirst
Set NodX = .Add(, , "menu", "Premier menu du treeview", 3, 4)
Do Until Rs.EOF
A = Rs.Fields("category")
B = Rs.Fields("category")
C = "menu"
Set NodX = .Add(C, tvwChild, A, B, 3, 4)
NodX.ForeColor = RGB(0, 128, 128)
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
'***********************************
'StrSql = "SELECT Clients.Société, Employés.Nom FROM Employés INNER JOIN ((Clients INNER JOIN Commandes ON Clients.[Code client] = Commandes.[Code client]) INNER JOIN [Détails commandes] ON Commandes.[N° commande] = [Détails commandes].[N° commande]) ON Employés.[N° employé] = Commandes.[N° employé] GROUP BY Clients.Société, Employés.Nom; "
StrSql = "SELECT category.category, category_1.category FROM category AS category_2 INNER JOIN (category AS category_1 INNER JOIN category ON category_1.parent = category.categoryID) ON category_2.parent = category_1.categoryID;"
Set Rs = Db.OpenRecordset(StrSql)
Rs.MoveFirst
Do Until Rs.EOF
A = Rs.Fields("category.category") & Rs.Fields("category_1.category")
B = Rs.Fields("category_1.category")
C = Rs.Fields("category.category")
Set NodX = .Add(C, tvwChild, A, B, 3, 4)
NodX.ForeColor = RGB(0, 128, 128)
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
'**************************************
'StrSql = "SELECT Clients.Société, Employés.Nom, Catégories.[Nom de catégorie] FROM (Catégories INNER JOIN Produits ON Catégories.[Code catégorie] = Produits.[Code catégorie]) INNER JOIN (Employés INNER JOIN ((Clients INNER JOIN Commandes ON Clients.[Code client] = Commandes.[Code client]) INNER JOIN [Détails commandes] ON Commandes.[N° commande] = [Détails commandes].[N° commande]) ON Employés.[N° employé] = Commandes.[N° employé]) ON Produits.[Réf produit] = [Détails commandes].[Réf produit] GROUP BY Clients.Société, Employés.Nom, Catégories.[Nom de catégorie];"
StrSql = "SELECT category.category, category_1.category, category_2.categoryID, category_2.category FROM category AS category_2 INNER JOIN (category AS category_1 INNER JOIN category ON category_1.parent = category.categoryID) ON category_2.parent = category_1.categoryID;"
Set Rs = Db.OpenRecordset(StrSql)
Rs.MoveFirst
Do Until Rs.EOF
A = Rs.Fields("category.category") & Rs.Fields("category_1.category") & "(P_)" & Rs.Fields("category_2.category")
B = Rs.Fields("category_2.category")
C = Rs.Fields("category.category") & Rs.Fields("category_1.category")
'Set NodX = .Add(C, tvwChild, A, B, 3, 4)
Set NodX = .Add(C, tvwChild, A, B, 6)
NodX.ForeColor = RGB(0, 128, 128)
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
'*************************************
'StrSql = "SELECT Clients.Société, Employés.Nom, Catégories.[Nom de catégorie], Produits.[Nom du produit], Sum([Détails commandes].Quantité) AS Qte, Sum([Détails commandes]![Prix unitaire]*[Détails commandes]![Quantité]) AS Mt FROM (Catégories INNER JOIN Produits ON Catégories.[Code catégorie] = Produits.[Code catégorie]) INNER JOIN (Employés INNER JOIN ((Clients INNER JOIN Commandes ON Clients.[Code client] = Commandes.[Code client]) INNER JOIN [Détails commandes] ON Commandes.[N° commande] = [Détails commandes].[N° commande]) ON Employés.[N° employé] = Commandes.[N° employé]) ON Produits.[Réf produit] = [Détails commandes].[Réf produit] GROUP BY Clients.Société, Employés.Nom, Catégories.[Nom de catégorie], Produits.[Nom du produit];"
'Set Rs = Db.OpenRecordset(StrSql)
'Rs.MoveFirst
'Do Until Rs.EOF
' A = Rs.Fields("Société") & Rs.Fields("Nom") & Rs.Fields("Nom de catégorie") & "(P_)" & Rs.Fields("Nom du produit")
' B = Rs.Fields("Nom du produit") & ". Quantité: " & Rs.Fields("Qte") & ". Montant: " & Rs.Fields("Mt")
' C = Rs.Fields("Société") & Rs.Fields("Nom") & Rs.Fields("Nom de catégorie")
' Set NodX = .Add(C, tvwChild, A, B, 6)
' NodX.ForeColor = RGB(128, 0, 0)
' Rs.MoveNext
'Loop
' Rs.Close
' Set Rs = Nothing
'**************************************
Fin_sub:
Set Menu = Nothing
NodX.EnsureVisible
End With
End Sub
Private Sub TreeView_DblClick()
On Error Resume Next
Dim NodX As node
Set NodX = TreeView.SelectedItem
LaPosition = InStr(1, NodX.Key, "(P_)")
If LaPosition = 0 Then Exit Sub
LaClé = Mid(NodX.Key, LaPosition + 4)
'MsgBox "Vous interrogez le produit : " & LaClé
MsgBox Val(TreeView.Nodes(1).Key)
End Sub |
Partager