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

IHM Discussion :

Association Module VBA bouton


Sujet :

IHM

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    50
    Détails du profil
    Informations personnelles :
    Âge : 74
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 50
    Points : 49
    Points
    49
    Par défaut Association Module VBA bouton
    Bonjour à tous !

    Je renouvelle ma demande précédente , car elle était marquée "Résolu" il y a quelques semaines, ce qui n'est pas tout à fait le cas ce jour...

    J'ai un premier module VBA (impression facture) appelé depuis le bouton correspondant qui fonctionne parfaitement..MAIS ...
    j'ai créé un bouton "calcultotaux" pour les factures saisies, avec un module VBA appelé Calcultotaux , qui fonctionne parfaitement , ....sous VBA uniquement !!! ...Impossible de lier le bouton "calcultotaux" au module correspondant, il affiche le module impression factures, en rajoutant au bas du code un "Private Sub-CommandXX-click , qui n'a rien à voir avec ce que je veux obtenir...Le lien entre le bouton et le module ne semble pas se faire , il confond les modules , ou les modules dans les formulaires, je ne sais plus trop quoi penser..
    Je pense n'être pas bien clair...
    Quelqu'un a-t'il une idée lumineuse ?

    Merci pour votre aide précieuse !

    Amicalement à tous,

    Fbourdon-Genève

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour

    Dans ton module tu as du créer une fonction?
    Comment appeles tu cette fonction à partir de l'évènement de ton bouton?

  3. #3
    Expert éminent sénior

    Avatar de Tofalu
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2004
    Messages
    9 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Octobre 2004
    Messages : 9 501
    Points : 32 311
    Points
    32 311
    Par défaut
    Un formulaire est lié à son module de classe, on ne peut pas le lier à un autre module. Ne ferais tu pas un amalgame entre fonction et module ?

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    50
    Détails du profil
    Informations personnelles :
    Âge : 74
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 50
    Points : 49
    Points
    49
    Par défaut
    Bonsoir , et Merci de vos 2 réponses...qui me font encore + nager ...Aïe !

    1) je n'ai pas créé de fonctions dans mes 2 modules ....
    2) Dans "Objets de classe" je vois le formulaire 'Gestion des impressions' , quand je clique dessus il m'affiche le code VBA "Impression factures" (correspondant au premier bouton "impression factures" , du moins je suppose...
    Or , comme je l'ai dit dans mon message ci-dessus , j'ai créé un autre bouton , dans ce même formulaire , calcultotaux , qui devrait être relié au code (module?) VBA "Calcultotaux" , qui fonctionne , sous VBA...Pourquoi ce code VBA n'apparaît pas quand je clique sur le formulaire "gestion des impressions" dans Objets de classe...

    Je suppose que je mélange tout , Help me please , tout ça n'est pas clair du tout pour moi ...

    J'ai acheté les énormes bouquins ACCESS2007 et VBA Office 2007 de chez Micro Application, je les potasse sans arrêt , mais alors là , ça coince...

    D'avance , merci !

    Fbourdon

  5. #5
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par fbourdon Voir le message
    Bonsoir , et Merci de vos 2 réponses...qui me font encore + nager ...Aïe !

    Or , comme je l'ai dit dans mon message ci-dessus , j'ai créé un autre bouton , dans ce même formulaire , calcultotaux , qui devrait être relié au code (module?) VBA "Calcultotaux" , qui fonctionne , sous VBA...Pourquoi ce code VBA n'apparaît pas quand je clique sur le formulaire "gestion des impressions" dans Objets de classe...

    Fbourdon
    Peux tu nous recopier le code qui fonctionne?

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    50
    Détails du profil
    Informations personnelles :
    Âge : 74
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 50
    Points : 49
    Points
    49
    Par défaut
    Voici les 2 codes VBA qui fonctionnent :

    le 1er fonctionne impeccablement avec bouton sur le formulaire (impression factures) :

    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
    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
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
     
    Option Compare Database
    Option Explicit
    Public xl As Excel.Application
    Public wbk As Excel.Workbook, wst As Excel.Worksheet
    Dim db As DAO.Database, rst As DAO.Recordset
    Public sstot1 As Integer, sstot2 As Integer, sstot As Integer
    Public Nblignes As Integer
    Public Libellé1A As String, Libellé1B As String, Libellé1C As String
    Public Quantité1 As Integer, Prixunitaire1 As Integer, Montant1 As Integer
    Public Libellé2A As String, Libellé2B As String, Libellé2C As String
    Public Quantité2 As Integer, Prixunitaire2 As Integer, Montant2 As Integer
    Public Libellé3A As String, Libellé3B As String, Libellé3C As String
    Public Quantité3 As Integer, Prixunitaire3 As Integer, Montant3 As Integer
    Public Libellé4A As String, Libellé4B As String, Libellé4C As String
    Public Quantité4 As Integer, Prixunitaire4 As Integer, Montant4 As Integer
    Public Libellé5A As String, Libellé5B As String, Libellé5C As String
    Public Quantité5 As Integer, Prixunitaire5 As Integer, Montant5 As Integer
    Public Libellé6A As String, Libellé6B As String, Libellé6C As String
    Public Quantité6 As Integer, Prixunitaire6 As Integer, Montant6 As Integer
    Public Libellé7A As String, Libellé7B As String, Libellé7C As String
    Public Quantité7 As Integer, Prixunitaire7 As Integer, Montant7 As Integer
    Public Libellé8A As String, Libellé8B As String, Libellé8C As String
    Public Quantité8 As Integer, Prixunitaire8 As Integer, Montant8 As Integer
    Public Libellé9A As String, Libellé9B As String, Libellé9C As String
    Public Quantité9 As Integer, Prixunitaire9 As Integer, Montant9 As Integer
    Public Libellé10A As String, Libellé10B As String, Libellé10C As String
    Public Quantité10 As Integer, Prixunitaire10 As Integer, Montant10 As Integer
    Public Nom As String, Adresse As String, Codepostal As String, Ville As String
    Public Réponse As Integer, strSQL As String
     
     
    Sub ImpressionFacture()
     
    Set db = CurrentDb
     
    'Saisie du numéro de facture pour impression
     
    Réponse = Val(InputBox("Saisissez le N° de facture Bok :", "Saisie N° Facture"))
     
    strSQL = "SELECT Factures.*, Clients.[Nom], Clients.[Adresse], Clients.[Codepostal], Clients.[Ville] FROM Clients RIGHT JOIN Factures ON Clients.[Id client] = Factures.[IdClient] WHERE [Factures].[FactureMB]=" & Réponse & ";"
     
    Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
     
     
    Set xl = New Excel.Application    ' Démarre Excel et ouvre la feuille Facture.xlsx
    xl.Visible = True
    Set wbk = xl.Workbooks.Open("C:\Documents and settings\Boks\FactureOK.xlsx")
     
    If rst("Nblignes") <= 6 Then       ' Traitement pour lignes de facture 1 à 6
     
        Set wst = wbk.Worksheets(1)    ' Feuille Excel 1
        With wst
        Début
     
    '***********************************************************************
    If rst("Nblignes") = 1 Then
            Procédure1
     
            sstot1 = Nz(rst("Montant1"))
    End If
    '***********************************************************************
    If rst("Nblignes") = 2 Then
            Procédure1
            Procédure2
            sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2"))
    End If
    '************************************************************
    If rst("Nblignes") = 3 Then
            Procédure1
            Procédure2
            Procédure3
            sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3"))
    End If
    '************************************************************
    If rst("Nblignes") = 4 Then
            Procédure1
            Procédure2
            Procédure3
            Procédure4
            sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3")) + Nz(rst("Montant4"))
    End If
    '***********************************************
    If rst("Nblignes") = 5 Then
            Procédure1
            Procédure2
            Procédure3
            Procédure4
            Procédure5
            sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3")) + Nz(rst("Montant4")) + Nz(rst("Montant5"))
    End If
    '***********************************************************************
    If rst("Nblignes") = 6 Then
            Procédure1
            Procédure2
            Procédure3
            Procédure4
            Procédure5
            Procédure6
            sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3")) + Nz(rst("Montant4")) + Nz(rst("Montant5")) + Nz(rst("Montant6"))
    End If
    '***************************************************************************
            wst.Range("D46").Value = "En votre aimable règlement"
     
            wst.Range("C48").Value = sstot1
            wst.Range("H48").Value = sstot1
     
            End With
     
    '*************************************************************************************
    Else  '(plus de 6 lignes de facture)
    '*************************************************************************************
     
        Set wst = wbk.Worksheets(1)     ' Feuille Excel 1
        With wst
            Début
            Procédure1
            Procédure2
            Procédure3
            Procédure4
            Procédure5
            Procédure6
            wst.Range("D46").Value = "En votre aimable règlement"
     
            wst.Range("C48").Value = sstot1
            wst.Range("H48").Value = sstot1
        End With
     
        ' Feuille Excel 2
     
        Set wst = wbk.Worksheets(2)
        With wst
     
            Début
            Select Case rst("Nblignes")
     
            Case 7
                Procédure7
            Case 8
                Procédure7
                Procédure8
            Case 9
                Procédure7
                Procédure8
                Procédure9
            Case 10
                Procédure7
                Procédure8
                Procédure9
                Procédure10
     
            End Select
     
            wst.Range("D46").Value = "En votre aimable règlement"
     
     
            If rst("Nblignes") = 7 Then
            sstot2 = Nz(rst("Montant7"))
            End If
            If rst("Nblignes") = 8 Then
            sstot2 = Nz(rst("Montant7")) + Nz(rst("Montant8"))
            End If
            If rst("Nblignes") = 9 Then
            sstot2 = Nz(rst("Montant7")) + Nz(rst("Montant8")) + Nz(rst("Montant9"))
            End If
            If rst("Nblignes") = 10 Then
            sstot2 = Nz(rst("Montant7")) + Nz(rst("Montant8")) + Nz(rst("Montant9")) + Nz(rst("Montant10"))
            End If
            sstot = sstot1 + sstot2
            wst.Range("C48").Value = sstot2
            wst.Range("H48").Value = sstot
     
          End With
    FIN:
    End If
    End Sub
     
     
     
     
    Sub Procédure1()
        wst.Range("B23").Value = rst("Quantité1")
        wst.Range("D23").Value = rst("Libellé1A")
        wst.Range("D24").Value = rst("Libellé1B")
        wst.Range("D25").Value = rst("Libellé1C")
        wst.Range("G23").Value = rst("Prixunitaire1")
        wst.Range("H23").Value = rst("Montant1")
    End Sub
     
    Sub Procédure2()
        wst.Range("B27").Value = rst("Quantité2")
        wst.Range("D27").Value = rst("Libellé2A")
        wst.Range("D28").Value = rst("Libellé2B")
        wst.Range("D29").Value = rst("Libellé2C")
        wst.Range("G27").Value = rst("Prixunitaire2")
        wst.Range("H27").Value = rst("Montant2")
    End Sub
     
    Sub Procédure3()
        wst.Range("B31").Value = rst("Quantité3")
        wst.Range("D31").Value = rst("Libellé3A")
        wst.Range("D32").Value = rst("Libellé3B")
        wst.Range("D33").Value = rst("Libellé3C")
        wst.Range("G31").Value = rst("Prixunitaire3")
        wst.Range("H31").Value = rst("Montant3")
    End Sub
     
    Sub Procédure4()
        wst.Range("B35").Value = rst("Quantité4")
        wst.Range("D35").Value = rst("Libellé4A")
        wst.Range("D36").Value = rst("Libellé4B")
        wst.Range("D37").Value = rst("Libellé4C")
        wst.Range("G35").Value = rst("Prixunitaire4")
        wst.Range("H35").Value = rst("Montant4")
    End Sub
     
    Sub Procédure5()
        wst.Range("B39").Value = rst("Quantité5")
        wst.Range("D39").Value = rst("Libellé5A")
        wst.Range("D40").Value = rst("Libellé5B")
        wst.Range("D41").Value = rst("Libellé5C")
        wst.Range("G39").Value = rst("Prixunitaire5")
        wst.Range("H39").Value = rst("Montant5")
    End Sub
     
    Sub Procédure6()
        wst.Range("B43").Value = rst("Quantité6")
        wst.Range("D43").Value = rst("Libellé6A")
        wst.Range("D44").Value = rst("Libellé6B")
        wst.Range("D45").Value = rst("Libellé6C")
        wst.Range("G43").Value = rst("Prixunitaire6")
        wst.Range("H43").Value = rst("Montant6")
    End Sub
     
    Sub Procédure7()
        wst.Range("B23").Value = rst("Quantité7")
        wst.Range("D23").Value = rst("Libellé7A")
        wst.Range("D24").Value = rst("Libellé7B")
        wst.Range("D25").Value = rst("Libellé7C")
        wst.Range("G23").Value = rst("Prixunitaire7")
        wst.Range("H23").Value = rst("Montant7")
    End Sub
     
    Sub Procédure8()
        wst.Range("B27").Value = rst("Quantité8")
        wst.Range("D27").Value = rst("Libellé8A")
        wst.Range("D28").Value = rst("Libellé8B")
        wst.Range("D29").Value = rst("Libellé8C")
        wst.Range("G27").Value = rst("Prixunitaire8")
        wst.Range("H27").Value = rst("Montant8")
    End Sub
     
    Sub Procédure9()
        wst.Range("B31").Value = rst("Quantité9")
        wst.Range("D31").Value = rst("Libellé9A")
        wst.Range("D32").Value = rst("Libellé9B")
        wst.Range("D33").Value = rst("Libellé9C")
        wst.Range("G31").Value = rst("Prixunitaire9")
        wst.Range("H31").Value = rst("Montant9")
    End Sub
     
    Sub Procédure10()
        wst.Range("B35").Value = rst("Quantité10")
        wst.Range("D35").Value = rst("Libellé10A")
        wst.Range("D36").Value = rst("Libellé10B")
        wst.Range("D37").Value = rst("Libellé10C")
        wst.Range("G35").Value = rst("Prixunitaire10")
        wst.Range("H35").Value = rst("Montant10")
    End Sub
     
    Sub Début()
        wst.Range("F9").Value = rst("Nom")
        wst.Range("F10").Value = rst("Adresse")
        wst.Range("F11").Value = rst("Codepostal")
        wst.Range("G11").Value = rst("Ville")
        wst.Range("C16").Value = rst("FactureMB")
        wst.Range("G16").Value = Date
        wst.Range("A19").Value = rst("Notre référence")
        wst.Range("B19").Value = rst("Mode d'envoi")
        wst.Range("D19").Value = rst("Votre référence")
        wst.Range("E19").Value = rst("Date de commande")
        wst.Range("G19").Value = rst("Date de livraison1")
        wst.Range("H19").Value = rst("IdClient")
    End Sub
    Le 2ème (CalculTotaux) ne fonctionne que sous VBA...J'ai enlevé les lignes de calcul redondantes pour vous...


    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
     
    Option Compare Database
    Option Explicit
    Dim db As DAO.Database, rst As DAO.Recordset
    Public FactureMB As String
    Public Montant1 As Integer, Quantité1 As Integer, Prixunitaire1 As Integer
    Public Montant2 As Integer, Quantité2 As Integer, Prixunitaire2 As Integer
    Public Montant3 As Integer, Quantité3 As Integer, Prixunitaire3 As Integer
    Public PrixTTC As Integer, Sous-total As Integer
    Public Réponse As Integer, strSQL As String
     
     
    Sub CalculTotaux()
     
    Set db = CurrentDb
    Set rst = db.OpenRecordset("Factures")
     
    'Saisie du numéro de facture pour calculs
     
    Réponse = Val(InputBox("Saisissez le N° de facture Boks :", "Calcul totaux par facture"))
    DoCmd.SetWarnings False
    strSQL = "UPDATE [Factures] SET [Montant1] = [Quantité1] * [Prixunitaire1] WHERE [Montant1] > 0 AND [Quantité1] > 0 AND [FactureMB]=" & Réponse & ";"
    DoCmd.RunSQL strSQL
     
    strSQL = "UPDATE [Factures] SET [Montant2] = [Quantité2] * [Prixunitaire2] WHERE [Prixunitaire2] > 0 AND [Quantité2] > 0 AND [FactureMB]=" & Réponse & ";"
    DoCmd.RunSQL strSQL
     
    strSQL = "UPDATE [Factures] SET [Montant3] = [Quantité3] * [Prixunitaire3] WHERE [Prixunitaire3] > 0 AND [Quantité3] > 0 AND [FactureMB]=" & Réponse & ";"
    DoCmd.RunSQL strSQL
     
    strSQL = "UPDATE [Factures] SET [Sous-total] = Nz([Montant1]) + Nz([Montant2]) + Nz([Montant3]) WHERE [FactureMB]=" & Réponse & ";"
    DoCmd.RunSQL strSQL
     
    ' pas de TVA pour l'instant,sans l'immatriculation officielle de l'entreprise.
     
    strSQL = "UPDATE [Factures] SET [PrixTTC] = Nz([Montant1]) + Nz([Montant2]) + Nz([Montant3]) WHERE [FactureMB]=" & Réponse & ";"
    DoCmd.RunSQL strSQL
     
    DoCmd.SetWarnings True
     
    End Sub
    Voilà...J'espère n'avoir rien oublié !

    Merci beaucoup pour votre aide !

    Amicalement à vous tous ,

    Fbourdon (Genève)

  7. #7
    Invité
    Invité(e)
    Par défaut
    Bonjour
    As tu un message d'erreur?
    Y a 'il bien marqué "procédure évènementielle sur l'èvènement OnClic de ton bouton?
    L'évènement appelle t-il bien ta procédure.
    Pour savoir si l'appel de ta procédure se fait bien, met une msgBox en début de module. Cela permet de voir si tu arrives bien dans ta fonction.

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    50
    Détails du profil
    Informations personnelles :
    Âge : 74
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 50
    Points : 49
    Points
    49
    Par défaut
    Bonsoir à tous !

    Je suppose avoir trouvé quelque chose , en faisant des essais, mais sans la garantie du gouvernement (Breveté SGDG...).

    Je pense qu'un seul formulaire se trouvant dans la catégorie 'MS ACCESS Objets de Classe' peut recevoir plusieurs procédures Sub-XXX-EndSub , chaque procédure différente ayant un code issu des différents modules , lequel code est appelé par un
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Private Sub CommandeXXX_Click()
    ImpressionBulletin (par exemple)
    End Sub
    Je ne sais pas si je suis bien clair !!!! I am right , or not ?

    Pas évident les notions de classe et tout ça ...Avez-vous un tutoriel quelque part ?

    J'espère votre 'feed-back' ...

    Amicalement à tous ,

    Fbourdon
    Genève

Discussions similaires

  1. Lancer un module VBA depuis un bouton
    Par fbourdon dans le forum IHM
    Réponses: 3
    Dernier message: 16/11/2009, 19h12
  2. Comment supprimer des boutons et les codes associés en vba
    Par Stargate SG1 dans le forum VBA Access
    Réponses: 4
    Dernier message: 06/12/2008, 19h47
  3. Récupération du mot de passe d'un module VBA dans access
    Par Doctor_M_387 dans le forum Access
    Réponses: 5
    Dernier message: 05/04/2006, 13h46
  4. Requête et Module VBA
    Par Telemak dans le forum Access
    Réponses: 1
    Dernier message: 15/10/2005, 13h04

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