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

Macros et VBA Excel Discussion :

interaction entre textbox et checkbox [XL-2007]


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Juin 2012
    Messages : 63
    Points : 39
    Points
    39
    Par défaut interaction entre textbox et checkbox
    Bonjour le forum,

    je rencontre un probleme suite à la création de textbox et checkbox dynamiques sur un usf

    je m'explique :
    je récupere dans des textbox des infos sur des commandes
    -numero de commande
    -date
    -montant total
    -versement
    -restant du
    -un textbox vide pour le remplir à la main du montant souhaité
    -une checkbox (et là mon probleme...)

    et ce pour chaque ligne d'un meme client

    j'aimerais qu'en cliquant sur le checkbox, le textbox vide (nommé txtprel) se remplisse du montant qui se trouve dans le textbox "restant du" se trouvant sur la meme ligne (donc ayant le meme numéro, cf code ci-dessous)

    dans l'usf
    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
    Sub Chercher_Click()
     
    Dim reponse ' As String
    Dim found ' As String
    Dim cell As Range
    Dim a As Range
    Dim Obj1 As Control, Obj2 As Control, Obj3 As Control, Obj4 As Control, Obj5 As Control, obj6 As Control, obj7 As Control, obj9 As Control
    Dim g As Integer, h As Integer, i As Integer, j As Integer, k As Integer, l As Integer, m As Integer
    Dim b As Integer
    Dim Posg As Long, Posh As Long, Posi As Long, Posj As Long, Posk As Long, Posl As Long, Posm As Long, z As Long, nb As Long
    Dim start1 As String
    Dim start2 As String
    Dim start3 As Currency, start4 As Currency, start5 As Currency
    Dim ctrl As Control
    Dim CtrlName As String
    Dim CtrlTotDu As Currency
    Dim Ctrlindex As Integer
     
    Set Collect = New Collection
     
    found = InputBox("n°clt svp")
    If Not found = vbNullString Then
    reponse = Nbrep(found)
    Else: Exit Sub
    End If
    '========================= boucle Factures=============================
    Posi = 12
    Posj = 84
    Posk = 156
    Posl = 228
    Posh = 300
    b = 40
    z = 2
      For i = 1 To reponse 'boucle pour la création des textbox
        Set Obj1 = Me.Controls.Add("forms.TextBox.1")
        Set Obj2 = Me.Controls.Add("forms.TextBox.1")
        Set Obj3 = Me.Controls.Add("forms.TextBox.1")
        Set Obj4 = Me.Controls.Add("forms.TextBox.1")
        Set Obj5 = Me.Controls.Add("forms.TextBox.1")
        If start1 = "" And start2 = "" And start3 = 0 And start4 = 0 And start5 = 0 Then
            Do While Trim(Worksheets("feuille").Cells(z, 1).Value) <> ""
            If Worksheets("feuille").Cells(z, 1).Value Like found Then
                start1 = Worksheets("feuille").Cells(z, 8).Value
                start2 = Worksheets("feuille").Cells(z, 9).Value
                start3 = Worksheets("feuille").Cells(z, 10).Value
                start4 = Worksheets("feuille").Cells(z, 11).Value
                start5 = Worksheets("feuille").Cells(z, 12).Value
                Exit Do
                End If
                z = z + 1
                Loop
            Else
                Do While Trim(Worksheets("feuille").Cells(z, 1).Value) <> ""
                    If Worksheets("feuille").Cells(z, 1).Value Like found Then
                        start1 = Worksheets("feuille").Cells(z + 1, 8).Value
                        start2 = Worksheets("feuille").Cells(z + 1, 9).Value
                        start3 = Worksheets("feuille").Cells(z + 1, 10).Value
                        start4 = Worksheets("feuille").Cells(z + 1, 11).Value & " €"
                        start5 = Worksheets("feuille").Cells(z + 1, 12).Value & " €"
                        z = z + 1
                        Exit Do
                    End If
                Loop
        End If
     
        With Obj1
            .Name = "TxtFact" & i
            .Object.Value = start1
            .Left = Posi
            .Top = 70 + b
            .Width = 50
            .Height = 20
        End With
        With Obj2
            .Name = "TxtDate" & i
            .Object.Value = start2
            .Left = Posj
            .Top = 70 + b
            .Width = 60
            .Height = 20
        End With
        With Obj3
            .Name = "TxtTotal" & i
            .Object.Value = start3
            .Left = Posk
            .Top = 70 + b
            .Width = 50
            .Height = 20
        End With
          'ajout de l'objet dans la classe
        Set cl3 = New classe3
        Set cl3.TxtTotal = Obj3
        Collect.Add cl3
     
        With Obj4
            .Name = "TxtAcpte" & i
            .Object.Value = start4
            .Left = Posl
            .Top = 70 + b
            .Width = 50
            .Height = 20
        End With
        With Obj5
            .Name = "TxtDu" & i
            .Object.Value = start5
            .Left = Posh
            .Top = 70 + b
            .Width = 50
            .Height = 20
        End With
            'ajout de l'objet dans la classe
        Set cl5 = New classe3
        Set cl5.TxtDu = Obj5
        Collect.Add cl5
     
        b = b + 40
    Next i
     
     
     
    '====================== boucle creation prelevement====================
    Posm = 374
    b = 40
    For m = 1 To reponse 'boucle pour la création des TextBox TxtPrel
        Set obj7 = Me.Controls.Add("forms.TextBox.1")
     
        With obj7
            .Name = "TxtPrel" & m
            '.Object.Value = "Prel" & m
            .Left = Posm
            .Top = 70 + b '* ((i - 1) Mod 5) + 40
            .Width = 50
            .Height = 20
        End With
     
     
        ''ajout de l'objet dans la classe
        Set cl7 = New classe3
        Set cl7.TxtPrel = obj7
        Collect.Add cl7
        ''If m Mod 5 = 0 Then Posi = Posi + 40
        b = b + 40
    Next m
     
    '================ boucle creation checkbox===========================
     
    Posg = 450
    b = 40
    For g = 1 To reponse 'boucle pour la création des CheckBox
        Set obj9 = Me.Controls.Add("forms.Checkbox.1")
        With obj9
            .Name = "ChkCpte" & g
            .Left = Posg
            .Top = 70 + b
            .Width = 15.75
        End With
     
        'ajout de l'objet dans la classe
        Set cl9 = New classe3
        Set cl9.ChkCpte = obj9
        Collect.Add cl9
        'If m Mod 5 = 0 Then Posi = Posi + 40
        b = b + 40
    Next g
     
    '===============================================================
     
     For Each ctrl In Me.Controls
               CtrlName = ctrl.Name
               If InStr(CtrlName, "TxtDu") = 1 Then
                    CtrlTotDu = CtrlTotDu + ctrl.Text
                End If
     Next
     txttotaldu = CtrlTotDu & " €"
    End Sub
    module de classe classe3 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Option Explicit
    Public WithEvents ChkCpte As MSForms.checkbox
    Public WithEvents TxtDu As MSForms.TextBox
    Public WithEvents TxtTotal As MSForms.TextBox
    Public WithEvents TxtPrel As MSForms.TextBox
    Il me semble bien avoir compris qu'il faut passer par un module de classe, mais malgré toute mes lectures ici même (merci Pierre Fauconnier et autres...), je n'y arrive pas...

    Est ce que quelqu'un peut m'aider svp

  2. #2
    Invité
    Invité(e)
    Par défaut bonjour,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub ChkCpte_Change()
    If ChkCpte.Value = True Then
        txtprel = TxtDu
    Else
        txtprel = ""
    End If
     
    End Sub

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Juin 2012
    Messages : 63
    Points : 39
    Points
    39
    Par défaut
    Bonjour Robert,

    merci pour cette réponse rapide.

    Quand je place le code dans le module de classe, j'ai une erreur "variable objet ou variable de bloc with non définie" sur la ligne
    Placé ailleurs je n'ai aucun résultat...

  4. #4
    Invité
    Invité(e)
    Par défaut bonjour,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     Set Obj1 = Me.Controls.Add("forms.TextBox.1")
        Set Obj2 = Me.Controls.Add("forms.TextBox.1")
        Set Obj3 = Me.Controls.Add("forms.TextBox.1")
        Set Obj4 = Me.Controls.Add("forms.TextBox.1")
        Set Obj5 = Me.Controls.Add("forms.TextBox.1")
    '...................................................................
     
    Set cl3 = New classe3
        Set cl3.TxtTotal = Obj3
        Collect.Add cl3
    dans ta class3
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Option Explicit
    Public WithEvents ChkCpte As MSForms.checkbox
    Public WithEvents TxtDu As MSForms.TextBox
    Public WithEvents TxtTotal As MSForms.TextBox
    Public WithEvents TxtPrel As MSForms.TextBox
    hors dans ta class3 je ne voie que l'afectation d'un contrôle
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      Set cl3.TxtTotal = Obj3
    commen veux tu utiliser les autre car par définition:
    Citation Envoyé par zealot37 Voir le message
    Bonjour Robert,

    merci pour cette réponse rapide.

    Quand je place le code dans le module de classe, j'ai une erreur "variable objet ou variable de bloc with non définie" sur la ligne
    Placé ailleurs je n'ai aucun résultat...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Set cl3 = New classe3
           Set cl3 = New classe3
        Set cl3.ChkCpte = Obj1
        Set cl3.TxtDu = Obj2
        Set cl3.TxtTotal = Obj3
        Set cl3.TxtPrel = Obj4
        Collect.Add cl3
        Set cl3 = Nothing
    en revanche
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Set Obj1 = Me.Controls.Add("forms.TextBox.1")
    n'est pas un checkbox

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Juin 2012
    Messages : 63
    Points : 39
    Points
    39
    Par défaut
    Merci Robert...
    malgré mes lectures j'avoue que je n'avais pas tout compris

    merci d'avoir éclairé mon chemin ! Je préfère comprendre quand ça fonctionne, c'est chose faite

    Et dans mon code, les checkbox c'est obj9

    Merci encore

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2013] Interaction entre deux checkbox
    Par matinho dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 19/06/2014, 13h50
  2. [Toutes versions] Interaction entre plusieurs textbox
    Par zouille dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 16/12/2013, 13h42
  3. [XL-2007] Interactions entre checkboxs de différents onglet
    Par sanguinair dans le forum Excel
    Réponses: 0
    Dernier message: 06/03/2011, 18h56
  4. [VB .Net][Forms] Interaction entre deux forms
    Par plasticgoat dans le forum Windows Forms
    Réponses: 7
    Dernier message: 24/08/2005, 13h14
  5. [Collaboration/Interaction] Peut-on schématiser une interaction entre un bouton de commande et un autre objet ?
    Par manel007 dans le forum Autres Diagrammes
    Réponses: 5
    Dernier message: 21/09/2004, 01h01

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