IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Access Discussion :

Treeview - récupérer/utiliser la valeur d'une node


Sujet :

VBA Access

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2003
    Messages : 4
    Points : 4
    Points
    4
    Par défaut Treeview - récupérer/utiliser la valeur d'une node
    Bonjour à tous
    J'utilise Access 2000
    Je suis loin d'être un expert en vba, en général je me débrouille, là je bloque

    J'ai une table category / 3 champs
    categoryID / parent / category
    Ca donne
    1 / 0 / anti
    2 / 1 / anti1.1
    3 / 2 / anti1.1.1
    etc

    J'ai crée un formulaire avec le tree view. Je le remplsi via ce code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Mais pour le dernier niveau je n'arrive pas à récupérer la valeur de categoryID
    J'ai l'id de la node mais pas plus

    Et deuxième problèmes, je voudrais que le tree s'ouvre/active selon le niveau qui a été sélectionné

    Je joins une petite image c'est toujours plus simple, le but étant d'attribuer une catégorie à un produit

    Merci pour votre aide. Je n'arrive pas à trouver de solution.

    Bertrand
    Images attachées Images attachées  

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2003
    Messages : 4
    Points : 4
    Points
    4
    Par défaut
    Y a t'il autre chose à utiliser qu'un treeview ?
    Cette option me semblait la plus performante, mais n'est pas très facile à utiliser :-(

    Bertrand

Discussions similaires

  1. Réponses: 5
    Dernier message: 07/02/2008, 11h18
  2. utiliser la valeur d'une colonne dans une requete
    Par docv266 dans le forum Requêtes
    Réponses: 4
    Dernier message: 20/08/2007, 15h44
  3. Utiliser la valeur d'une variable string
    Par vador972 dans le forum Access
    Réponses: 11
    Dernier message: 14/08/2006, 21h26
  4. Utilise la valeur d'une textbox dans une requête sql
    Par podidoo dans le forum Requêtes et SQL.
    Réponses: 4
    Dernier message: 29/03/2006, 09h53
  5. Utiliser la valeur d'une checkbox sous HTMLDB
    Par zent dans le forum Oracle
    Réponses: 5
    Dernier message: 03/11/2005, 17h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo