Ajouter des text box dans un userform

Résolu
titi17-08 Messages postés 123 Statut Membre -  
titi17-08 Messages postés 123 Statut Membre -
Bonsoir le forum,
dans un userform , avec un bouton je vais chercher un nombre variable (selon le nombre de cellule non-vide)allant de 1 à ....
avec ce nombre variable je souhaiterais insérer des textbox dans mon formulaire égal au nombre variable ...
en réglant la hauteur et positionnement de chacun.
je ne demande pas le code complet mais une orientation vers l'insertion des textbox sachant que j'ai déjà une ligne de textbox qui pourrait me servir de modele et de les dupliquer.

merci
et bonnes fêtes de fin d'année ;)
Titi

4 réponses

  1. M-12 Messages postés 1349 Statut Membre 285
     
    Bonjour,
    Voici un exemple pour t'avancer dans ton projet
    https://www.cjoint.com/c/KLqggEA8Xsv
    1
    1. titi17-08 Messages postés 123 Statut Membre 1
       
      Bonjour M-12,
      merci je viens de jeter un oeil sans faire le code sur mon projet, et je n'avais pas pris connaissance des modules de classe pour le text forms.
      cela semble correspondre a mes interrogations .
      Je reviens vers toi dès que j'ai avancé dessus
      merci et belle journée
      titi
      0
  2. M-12 Messages postés 1349 Statut Membre 285
     
    Regarde bien mon exemple, et tu verras que ce n'est pas la même procèdure
    Mais n'oublie pas de mettre aussi cette ligne dans un module
    Bref il faut bien copier/coller les bonnes macros
    1
    1. titi17-08 Messages postés 123 Statut Membre 1
       
      Bonjour M-12
      alors j'ai regardé avec des points d'arrêt sur mon code ,
      il me crée les textbox dans mon premier userform et une fois le nombre demandé il m'ouvre l'userform concerné par les ajouts sans avir ajouté les textbox et pourtant j'ai mis le with en notifiant l'userform voulu ...
      voici le code
      merci pour votre aide

      Private Sub Valider_Les_Dates_Click()
      Dim cherche As Variant
      Dim chercheF As Variant
      Dim c As Variant
      Dim NT As Variant
      Dim LL As Long
      Dim Ln As Long
      Dim Lp As Long
      Dim Lc As Long
      Dim Lnb As Long
      Dim Lt As Long
      Dim Lm As Long
      Dim Lch As Long
      Dim Lw As Long
      Dim Ls As Long
      Dim Le As Long
      Dim H As Long
      Dim Cl As Classe1
      Dim Obj As Control
      Dim montexte2 As Control
      Dim premier As Variant
      Dim Nbre_Free_Lance As Integer
      Dim Nbre_Free_LanceT As Integer
      Dim cell As Variant
      Set Collect = New Collection
      cherche = Me.Debut_Facturation_M & " " & Me.Debut_Facturationt_A
      chercheF = Me.Fin_Facturation_M & " " & Me.Fin_de_Facturation_A
      LL = 6
      H = 25.5
      Ln = 132
      Lp = 126
      Lc = 108
      Lnb = 36
      Lt = 66
      Lm = 48
      Lch = 90
      Lw = 66
      Ls = 66
      Le = 49
      Nbre_Free_Lance = 0
      With Liste_Freelance_periode
      .Debut_de_Facturation = Me.Debut_Facturation_J & " " & Me.Debut_Facturation_M & " " & Me.Debut_Facturationt_A
      .Fin_De_Facturation = Me.Fin_Facturation_J & " " & Me.Fin_Facturation_M & " " & Me.Fin_de_Facturation_A
      If Me.Debut_Facturation_M = Me.Fin_Facturation_M Then
      Worksheets(cherche).Select
      With Columns(2)
      Set c = .Cells.Find("Nom", , xlValues, xlWhole, , , False)
      If Not c Is Nothing Then

      premier = c.Select
      Selection.Offset(1, 0).Select

      Do While Selection.Offset(0, 0) <> ""
      Selection.Offset(1, 0).Select
      Nbre_Free_Lance = Nbre_Free_Lance + 1

      Loop
      MsgBox (Nbre_Free_Lance)
      With Liste_Freelance_periode

      End With
      With Liste_Freelance_periode
      c.Select
      Selection.Offset(1, 0).Select
      .Valider_les_freelances.Top = 168 + H + (Nbre_Free_Lance * (H + LL))
      .retour.Top = 168 + H + (Nbre_Free_Lance * (H + LL))
      .Height = 168 + H + (Nbre_Free_Lance * (H + LL)) + 80
      .Nom_1 = Selection.Offset.Value
      .Prenom_1 = Selection.Offset(0, 1).Value
      .Client_1 = Selection.Offset(0, 17).Value
      .Nbjrs_1 = Selection.Offset(0, 22).Value
      .TJM_1 = Selection.Offset(0, 6).Value
      .TJM_1.Value = Format(.TJM_1.Value, "#,##0.0 €")
      .Marge_1 = Selection.Offset(0, 7).Value
      .Marge_1.Value = Format(.Marge_1.Value, "#,##0.0 €")
      .Chiffre_1 = Selection.Offset(0, 23).Value
      .Chiffre_1.Value = Format(.Chiffre_1.Value, "#,##0.0 €")
      .WOW_1 = Selection.Offset(0, 24).Value
      .WOW_1.Value = Format(.WOW_1.Value, "#,##0.0 €")
      .SJTC_1 = Selection.Offset(0, 25).Value
      .SJTC_1.Value = Format(.SJTC_1.Value, "#,##0.0 €")



      End With

      Selection.Offset(1, 0).Select
      For NT = 1 To Nbre_Free_Lance
      Set Obj = Me.Controls.Add("Forms.TextBox.1")
      MsgBox ("un nouveau") ' ca c'est pour verifier ou la création du textbox se fait :)
      With Obj
      .Name = "Nom_" & (NT + 1)
      .Object.Value = "Nom_" & (NT + 1)
      .Left = LL
      .Top = 168 + LL + (H * NT)
      .Width = Ln
      .Height = H
      End With
      Set Cl = New Classe1
      Set Cl.TextBox = Obj
      Collect.Add Cl


      Next NT

      End If
      End With
      Else
      MsgBox ("attention il y a plusieurs mois de facturation")
      End If
      End With
      Liste_Freelance_periode.Show

      Unload Me
      End Sub
      0
      1. titi17-08 Messages postés 123 Statut Membre 1 > titi17-08 Messages postés 123 Statut Membre
         
        Bonjour le forum,
        j'ai trouve mon petit problème en fait je n'appelé pas le bon userform pour interagir dessus
        voici le code au cas ou
        belle journée

        Private Sub Valider_Les_Dates_Click()
        Dim cherche As Variant
        Dim chercheF As Variant
        Dim c As Variant
        Dim NT As Variant
        Dim LL As Long
        Dim Ln As Long
        Dim Lp As Long
        Dim Lc As Long
        Dim Lnb As Long
        Dim Lt As Long
        Dim Lm As Long
        Dim Lch As Long
        Dim Lw As Long
        Dim Ls As Long
        Dim Le As Long
        Dim H As Long
        Dim Cl As Classe1
        Dim Obj As Control
        Dim Nts As Control
        Dim montexte2 As Control
        Dim premier As Variant
        Dim Nbre_Free_Lance As Integer
        Dim Nbre_Free_LanceT As Integer
        Dim cell As Variant
        Set Collect = New Collection
        cherche = Me.Debut_Facturation_M & " " & Me.Debut_Facturationt_A
        chercheF = Me.Fin_Facturation_M & " " & Me.Fin_de_Facturation_A
        LL = 6
        H = 25.5
        Ln = 132
        Lp = 126
        Lc = 108
        Lnb = 36
        Lt = 66
        Lm = 48
        Lch = 90
        Lw = 66
        Ls = 60
        Le = 49
        Nbre_Free_Lance = 0
        With Liste_Freelance_periode
        .Debut_de_Facturation = Me.Debut_Facturation_J & " " & Me.Debut_Facturation_M & " " & Me.Debut_Facturationt_A
        .Fin_De_Facturation = Me.Fin_Facturation_J & " " & Me.Fin_Facturation_M & " " & Me.Fin_de_Facturation_A
        If Me.Debut_Facturation_M = Me.Fin_Facturation_M Then
        Worksheets(cherche).Select
        With Columns(2)
        Set c = .Cells.Find("Nom", , xlValues, xlWhole, , , False)
        If Not c Is Nothing Then
        premier = c.Select
        Selection.Offset(1, 0).Select
        Do While Selection.Offset(0, 0) <> ""
        Selection.Offset(1, 0).Select
        Nbre_Free_Lance = Nbre_Free_Lance + 1
        Loop
        For NT = 1 To (Nbre_Free_Lance - 1)
        With Liste_Freelance_periode
        c.Select
        Selection.Offset(1, 0).Select
        '------TextBox Nom-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")
        With Obj
        .Name = "Nom_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 0).Value
        .FontSize = 12
        .FontBold = True
        .TextAlign = 2
        .Left = LL
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Ln
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox Prenom-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "Prenom_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 1).Value
        .FontSize = 12
        .FontBold = True
        .TextAlign = 2
        .Left = ((2 * LL) + Ln)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Lp
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox Client-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "Client_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 17).Value
        .FontSize = 12
        .FontBold = True
        .TextAlign = 2
        .Left = ((3 * LL) + Ln + Lp)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Lc
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox Nombre de jours-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "Nbjrs_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 22).Value
        .FontSize = 12
        .FontBold = True
        .TextAlign = 2
        .Left = ((4 * LL) + Ln + Lp + Lc)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Lnb
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox TJM-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "TJM_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 6).Value
        .Object.Value = Format(.Object.Value, "#,##0.0 €")
        .FontSize = 10
        .FontBold = True
        .TextAlign = 2
        .Left = ((5 * LL) + Ln + Lp + Lc + Lnb)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Lt
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox Marge-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "Marge_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 7).Value
        .Object.Value = Format(.Object.Value, "#,##0.0 €")
        .FontSize = 10
        .FontBold = True
        .TextAlign = 2
        .Left = ((6 * LL) + Ln + Lp + Lc + Lnb + Lt)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Lm
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox Chiffre-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "Chiffre_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 23).Value
        .Object.Value = Format(.Object.Value, "#,##0.0 €")
        .FontSize = 10
        .FontBold = True
        .TextAlign = 2
        .Left = ((7 * LL) + Ln + Lp + Lc + Lnb + Lt + Lm)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Lch
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox WOW-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "Wow_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 24).Value
        .Object.Value = Format(.Object.Value, "#,##0.0 €")
        .FontSize = 10
        .FontBold = True
        .TextAlign = 2
        .Left = ((8 * LL) + Ln + Lp + Lc + Lnb + Lt + Lm + Lch)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Lw
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox Sjtc-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.TextBox.1")

        With Obj
        .Name = "Sjtc_" & (NT + 1)
        .Object.Value = Selection.Offset(NT, 25).Value
        .Object.Value = Format(.Object.Value, "#,##0.0 €")
        .FontSize = 10
        .FontBold = True
        .TextAlign = 2
        .Left = ((9 * LL) + Ln + Lp + Lc + Lnb + Lt + Lm + Lch + Lw)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Ls
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.TextBox = Obj
        Collect.Add Cl
        '------TextBox Eff-----
        Set Obj = Liste_Freelance_periode.Controls.Add("forms.checkbox.1")

        With Obj
        .Name = "Eff_" & (NT + 1)
        '.Object.Value = "Sjtc_" & (NT + 1)
        .Left = ((10 * LL) + Ln + Lp + Lc + Lnb + Lt + Lm + Lch + Lw + Ls)
        .Top = ((168 + (NT * LL)) + (H * NT))
        .Width = Le
        .Height = H
        End With
        Set Cl = New Classe1
        Set Cl.CheckBox = Obj
        Collect.Add Cl

        End With
        Next NT

        With Liste_Freelance_periode
        c.Select
        Selection.Offset(1, 0).Select
        .Valider_les_freelances.Top = 168 + H + (Nbre_Free_Lance * (H + LL))
        .retour.Top = 168 + H + (Nbre_Free_Lance * (H + LL))
        .Height = 168 + H + (Nbre_Free_Lance * (H + LL)) + 80
        .Nom_1 = Selection.Offset.Value
        .Prenom_1 = Selection.Offset(0, 1).Value
        .Client_1 = Selection.Offset(0, 17).Value
        .Nbjrs_1 = Selection.Offset(0, 22).Value
        .TJM_1 = Selection.Offset(0, 6).Value
        .TJM_1.Value = Format(.TJM_1.Value, "#,##0.0 €")
        .Marge_1 = Selection.Offset(0, 7).Value
        .Marge_1.Value = Format(.TJM_1.Value, "#,##0.0 €")
        .Chiffre_1 = Selection.Offset(0, 23).Value
        .Chiffre_1.Value = Format(.TJM_1.Value, "#,##0.0 €")
        .WOW_1 = Selection.Offset(0, 24).Value
        .WOW_1.Value = Format(.TJM_1.Value, "#,##0.0 €")
        .SJTC_1 = Selection.Offset(0, 25).Value
        .SJTC_1.Value = Format(.TJM_1.Value, "#,##0.0 €")



        End With

        Selection.Offset(1, 0).Select

        End If
        End With
        Else
        MsgBox ("attention il y a plusieurs mois de facturation")
        End If
        End With
        Liste_Freelance_periode.Show

        Unload Me
        End Sub
        0
  3. titi17-08 Messages postés 123 Statut Membre 1
     
    Bonjour M-12
    j'ai adapté ton code a mon useform:
    je n'ai pas de création de textebox supplémentaire en variable avec mon nombre de lignes trouvées.
    voici le code
    merci par avance
    Titi
     Sub Valider_Les_Dates_Click()
    Dim cherche As Variant
    Dim chercheF As Variant
    Dim c As Variant
    Dim NT As Long
    Dim LL As Long
    Dim Ln As Long
    Dim Lp As Long
    Dim Lc As Long
    Dim Lnb As Long
    Dim Lt As Long
    Dim Lm As Long
    Dim Lch As Long
    Dim Lw As Long
    Dim Ls As Long
    Dim Le As Long
    Dim H As Long
    Dim Cl As Classe1
    Dim montexte1 As Control
    Dim montexte2 As Control
    Dim premier As Variant
    Dim Nbre_Free_Lance As Integer
    cherche = Me.Debut_Facturation_M & " " & Me.Debut_Facturationt_A
    chercheF = Me.Fin_Facturation_M & " " & Me.Fin_de_Facturation_A
    LL = 6
    H = 25.5
    Ln = 132
    Lp = 126
    Lc = 108
    Lnb = 36
    Lt = 66
    Lm = 48
    Lch = 90
    Lw = 66
    Ls = 66
    Le = 49
    Nbre_Free_Lance = 0
    With Liste_Freelance_periode
    .Debut_de_Facturation = Me.Debut_Facturation_J & " " & Me.Debut_Facturation_M & " " & Me.Debut_Facturationt_A
    .Fin_De_Facturation = Me.Fin_Facturation_J & " " & Me.Fin_Facturation_M & " " & Me.Fin_de_Facturation_A
    If Me.Debut_Facturation_M = Me.Fin_Facturation_M Then
    Worksheets(cherche).Select
    With Columns(2)
    Dim cell As Variant
    Set Collect = New Collection
    Set c = .Cells.Find("Nom", , xlValues, xlWhole, , , False)
    If Not c Is Nothing Then

    premier = c.Select
    Selection.Offset(1, 0).Select

    Do While Selection.Offset(0, 0) <> ""
    Selection.Offset(1, 0).Select
    Nbre_Free_Lance = Nbre_Free_Lance + 1

    Loop
    MsgBox (Nbre_Free_Lance)
    For NT = 1 To Nbre_Free_Lance
    With Liste_Freelance_periode

    Set montexte1 = Me.Controls.Add("Forms.TextBox.1")
    With montexte1
    .Name = "Nom_" & NT
    .Object.Value = "Nom_" & NT
    .Left = LL
    .Top = 168 + LL + H
    .Width = Ln
    .Height = H

    End With

    Set Cl = New Classe1
    Set Cl.TextBox = montexte1
    Collect.Add Cl
    End With
    Next NT
    c.Select
    Selection.Offset(1, 0).Select

    With Liste_Freelance_periode
    .Valider_les_freelances.Top = 168 + H + (Nbre_Free_Lance * (H + LL))
    .retour.Top = 168 + H + (Nbre_Free_Lance * (H + LL))
    .Height = 168 + H + (Nbre_Free_Lance * (H + LL)) + 80
    .Nom_1 = Selection.Offset.Value
    .Prenom_1 = Selection.Offset(0, 1).Value
    .Client_1 = Selection.Offset(0, 17).Value
    .Nbjrs_1 = Selection.Offset(0, 22).Value
    .TJM_1 = Selection.Offset(0, 6).Value
    .TJM_1.Value = Format(.TJM_1.Value, "#,##0.0 €")
    .Marge_1 = Selection.Offset(0, 7).Value
    .Marge_1.Value = Format(.Marge_1.Value, "#,##0.0 €")
    .Chiffre_1 = Selection.Offset(0, 23).Value
    .Chiffre_1.Value = Format(.Chiffre_1.Value, "#,##0.0 €")
    .WOW_1 = Selection.Offset(0, 24).Value
    .WOW_1.Value = Format(.WOW_1.Value, "#,##0.0 €")
    .SJTC_1 = Selection.Offset(0, 25).Value
    .SJTC_1.Value = Format(.SJTC_1.Value, "#,##0.0 €")
    End With
    Selection.Offset(1, 0).Select

    End If
    End With
    Else
    MsgBox ("attention il y a plusieurs mois de facturation")
    End If
    End With
    Liste_Freelance_periode.Show
    Unload Me
    End Sub
    0
    1. M-12 Messages postés 1349 Statut Membre 285
       
      Bonjour,
      Par rapport à mon exemple, as-tu créé le module de Classe
      Sans voir le classeur, avec son USF, pas facile de t'aider
      0
  4. titi17-08 Messages postés 123 Statut Membre 1
     
    Bonjour,
    alors j'ai crée un module de classe avec le code
    Option Explicit

    Public WithEvents TextBox As MSForms.TextBox

    est ce bien cela que tu demandes ?
    ou diis je crée un exemple de textbox quelque part?
    mon fichier est rempli de données confidentielles et il m'est difficile de le transférer sinon je l'aurai déjà donné ;)
    merci
    0