Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Création dynamique de form

3 réponses
Avatar
Frederic
Bonjour à tous, j'ai a nouveau besoin d'aide!
Je crée de maniére dynamique un form représentant un Ordre de Fab. Celui ci
est donc toujours le meme, sauf son nom et intitulé qui change.Ensuite , je
crée par code les labels et textbox de ce form.
Mon proble est que le nom du form est lié à une variable et le code me
retourne une erreur a cause du nom.
Voici mon code: Si quelqu'un pouvait m'aider.
Merci
Dim BarForm As Object, p As Variant, q As Integer, N As Variant
Dim L1 As MSForms.Label, L2 As MSForms.Label, L3 As MSForms.Label
Dim T1 As MSForms.textbox, T2 As MSForms.textbox, T3 As MSForms.textbox


Function CreationOF()
Dim q As Integer, p As Variant

p = Worksheets("CommandeCLIENT").Range("C1000").End(xlUp).Value
q = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value -
Worksheets("STOCKprod").Range("A3:D" &
Range("A1000").End(xlUp).Row).Find(p).Offset(0, 3).Value
N = Worksheets("CommandeCLIENT").Range("A1000").End(xlUp).Value


'userform

Set BarForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With BarForm
.Properties("Caption") = " OF " & N
.Properties("Width") = 130
.Properties("Height") = 150
End With

'label sur userform
Set L1 = BarForm.Controls.Add("forms.label.1", "Label1", True)
With L1
.Text = "Produit"
.Left = 5
.Top = 5
.Width = 120
.Height = 18
.Name = "Label1"
.Font.Bold = True
.Font.Size = 10
End With
Set L2 = BarForm.Controls.Add("forms.label.1", "Label2", True)
With L2
.Text = "Quantité"
.Left = 1
.Top = 50
.Width = 50
.Height = 18
.Name = "Label2"
.Font.Bold = True
.Font.Size = 10
End With
Set L3 = BarForm.Controls.Add("forms.label.1", "Label3", True)
With L3
.Text = "Délai"
.Left = 1
.Top = 70
.Width = 50
.Height = 18
.Name = "Label3"
.Font.Bold = True
.Font.Size = 10
End With
'textbox sur userform
Set T1 = BarForm.Controls.Add("forms.textbox.1", "textbox1", True)
With T1
.Text = p
.Left = 5
.Top = 25
.Width = 120
.Height = 18
.Name = "textbox1"
.Font.Bold = True
.Font.Size = 10
End With
Set T2 = BarForm.Controls.Add("forms.textbox.1", "textbox2", True)
With T2
.Text = q
.Left = 55
.Top = 50
.Width = 44
.Height = 18
.Name = "textbox2"
.Font.Bold = True
.Font.Size = 10
End With
Set T3 = BarForm.Controls.Add("forms.textbox.1", "textbox3", True)
With T3
.Text =
Worksheets("CommandeCLIENT").Range("E1000").End(xlUp).Value
.Left = 55
.Top = 70
.Width = 44
.Height = 18
.Name = "textbox3"
.Font.Bold = True
.Font.Size = 10
End With

End Function

3 réponses

Avatar
michdenis
Bonjour Frédéric,

Je n'ai pas testé ton code... mais tu dois avoir un problème là :

q = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value -
Worksheets("STOCKprod").Range("A3:D" &
Range("A1000").End(xlUp).Row).Find(p).Offset(0, 3).Value

ça devrait plutôt ressembler à ceci :


s = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value
with Worksheets("STOCKprod")
With .Range("A3:D" & .Range("A1000").End(xlUp).Row).
r= .Find(p).Offset(0, 3).Value
End with
End with
Q = S - R

Il doit y avoir un point devant chaque "Range" pour siginifier quelle est la
feuille source de la plage.
.Range("A3:D" & .Range("A1000").End(xlUp).Row).


P.S. La méthode Find ... si tu n'utilises pas certains PARAMÈTRES va finir par te causer
des problèmes... prend le temps de lire dans l'aide toute l'information sur
cette méthode...

C'est spécial .... car la méthode recherche dans A3:Dx et peu importe où elle
trouve l'information (colonne) , tu extraits toujours la valeur 3 colonnes à droite !!!! ?


Salutations!






"Frederic" a écrit dans le message de news:

Bonjour à tous, j'ai a nouveau besoin d'aide!
Je crée de maniére dynamique un form représentant un Ordre de Fab. Celui ci
est donc toujours le meme, sauf son nom et intitulé qui change.Ensuite , je
crée par code les labels et textbox de ce form.
Mon proble est que le nom du form est lié à une variable et le code me
retourne une erreur a cause du nom.
Voici mon code: Si quelqu'un pouvait m'aider.
Merci
Dim BarForm As Object, p As Variant, q As Integer, N As Variant
Dim L1 As MSForms.Label, L2 As MSForms.Label, L3 As MSForms.Label
Dim T1 As MSForms.textbox, T2 As MSForms.textbox, T3 As MSForms.textbox


Function CreationOF()
Dim q As Integer, p As Variant

p = Worksheets("CommandeCLIENT").Range("C1000").End(xlUp).Value
q = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value -
Worksheets("STOCKprod").Range("A3:D" &
Range("A1000").End(xlUp).Row).Find(p).Offset(0, 3).Value
N = Worksheets("CommandeCLIENT").Range("A1000").End(xlUp).Value


'userform

Set BarForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With BarForm
.Properties("Caption") = " OF " & N
.Properties("Width") = 130
.Properties("Height") = 150
End With

'label sur userform
Set L1 = BarForm.Controls.Add("forms.label.1", "Label1", True)
With L1
.Text = "Produit"
.Left = 5
.Top = 5
.Width = 120
.Height = 18
.Name = "Label1"
.Font.Bold = True
.Font.Size = 10
End With
Set L2 = BarForm.Controls.Add("forms.label.1", "Label2", True)
With L2
.Text = "Quantité"
.Left = 1
.Top = 50
.Width = 50
.Height = 18
.Name = "Label2"
.Font.Bold = True
.Font.Size = 10
End With
Set L3 = BarForm.Controls.Add("forms.label.1", "Label3", True)
With L3
.Text = "Délai"
.Left = 1
.Top = 70
.Width = 50
.Height = 18
.Name = "Label3"
.Font.Bold = True
.Font.Size = 10
End With
'textbox sur userform
Set T1 = BarForm.Controls.Add("forms.textbox.1", "textbox1", True)
With T1
.Text = p
.Left = 5
.Top = 25
.Width = 120
.Height = 18
.Name = "textbox1"
.Font.Bold = True
.Font.Size = 10
End With
Set T2 = BarForm.Controls.Add("forms.textbox.1", "textbox2", True)
With T2
.Text = q
.Left = 55
.Top = 50
.Width = 44
.Height = 18
.Name = "textbox2"
.Font.Bold = True
.Font.Size = 10
End With
Set T3 = BarForm.Controls.Add("forms.textbox.1", "textbox3", True)
With T3
.Text Worksheets("CommandeCLIENT").Range("E1000").End(xlUp).Value
.Left = 55
.Top = 70
.Width = 44
.Height = 18
.Name = "textbox3"
.Font.Bold = True
.Font.Size = 10
End With

End Function
Avatar
Frederic
Merci pour ta réponse. En effet j'avais mis de coté ce probleme, et mesrci de
m'apporter la méthode.
Par contre as tu une idée pour lmon probleme précédement exprimé?
L'erreur apparait ici
'label sur userform
Set L1 = BarForm.Controls.Add("forms.label.1", "Label1", True)
C'est une erreur par rapport à l'objet.

J'avais essayé de mettre lors de la création du form sa
.Properties("Name")="of"& N
Mais j'avais alors une erreur pour le nom.

C'est pourtant l'architecture que je doit avoir afin de pouvoir, lors de la
déclaration de fab, appeler et supprimer l' of concerné.

Peut tu m'aider.
Je potasse en attendant la propriete Find.
Merci

Bonjour Frédéric,

Je n'ai pas testé ton code... mais tu dois avoir un problème là :

q = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value -
Worksheets("STOCKprod").Range("A3:D" &
Range("A1000").End(xlUp).Row).Find(p).Offset(0, 3).Value

ça devrait plutôt ressembler à ceci :


s = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value
with Worksheets("STOCKprod")
With .Range("A3:D" & .Range("A1000").End(xlUp).Row).
r= .Find(p).Offset(0, 3).Value
End with
End with
Q = S - R

Il doit y avoir un point devant chaque "Range" pour siginifier quelle est la
feuille source de la plage.
..Range("A3:D" & .Range("A1000").End(xlUp).Row).


P.S. La méthode Find ... si tu n'utilises pas certains PARAMÈTRES va finir par te causer
des problèmes... prend le temps de lire dans l'aide toute l'information sur
cette méthode...

C'est spécial .... car la méthode recherche dans A3:Dx et peu importe où elle
trouve l'information (colonne) , tu extraits toujours la valeur 3 colonnes à droite !!!! ?


Salutations!






"Frederic" a écrit dans le message de news:

Bonjour à tous, j'ai a nouveau besoin d'aide!
Je crée de maniére dynamique un form représentant un Ordre de Fab. Celui ci
est donc toujours le meme, sauf son nom et intitulé qui change.Ensuite , je
crée par code les labels et textbox de ce form.
Mon proble est que le nom du form est lié à une variable et le code me
retourne une erreur a cause du nom.
Voici mon code: Si quelqu'un pouvait m'aider.
Merci
Dim BarForm As Object, p As Variant, q As Integer, N As Variant
Dim L1 As MSForms.Label, L2 As MSForms.Label, L3 As MSForms.Label
Dim T1 As MSForms.textbox, T2 As MSForms.textbox, T3 As MSForms.textbox


Function CreationOF()
Dim q As Integer, p As Variant

p = Worksheets("CommandeCLIENT").Range("C1000").End(xlUp).Value
q = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value -
Worksheets("STOCKprod").Range("A3:D" &
Range("A1000").End(xlUp).Row).Find(p).Offset(0, 3).Value
N = Worksheets("CommandeCLIENT").Range("A1000").End(xlUp).Value


'userform

Set BarForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With BarForm
.Properties("Caption") = " OF " & N
.Properties("Width") = 130
.Properties("Height") = 150
End With

'label sur userform
Set L1 = BarForm.Controls.Add("forms.label.1", "Label1", True)
With L1
.Text = "Produit"
.Left = 5
.Top = 5
.Width = 120
.Height = 18
.Name = "Label1"
.Font.Bold = True
.Font.Size = 10
End With
Set L2 = BarForm.Controls.Add("forms.label.1", "Label2", True)
With L2
.Text = "Quantité"
.Left = 1
.Top = 50
.Width = 50
.Height = 18
.Name = "Label2"
.Font.Bold = True
.Font.Size = 10
End With
Set L3 = BarForm.Controls.Add("forms.label.1", "Label3", True)
With L3
.Text = "Délai"
.Left = 1
.Top = 70
.Width = 50
.Height = 18
.Name = "Label3"
.Font.Bold = True
.Font.Size = 10
End With
'textbox sur userform
Set T1 = BarForm.Controls.Add("forms.textbox.1", "textbox1", True)
With T1
.Text = p
.Left = 5
.Top = 25
.Width = 120
.Height = 18
.Name = "textbox1"
.Font.Bold = True
.Font.Size = 10
End With
Set T2 = BarForm.Controls.Add("forms.textbox.1", "textbox2", True)
With T2
.Text = q
.Left = 55
.Top = 50
.Width = 44
.Height = 18
.Name = "textbox2"
.Font.Bold = True
.Font.Size = 10
End With
Set T3 = BarForm.Controls.Add("forms.textbox.1", "textbox3", True)
With T3
.Text > Worksheets("CommandeCLIENT").Range("E1000").End(xlUp).Value
.Left = 55
.Top = 70
.Width = 44
.Height = 18
.Name = "textbox3"
.Font.Bold = True
.Font.Size = 10
End With

End Function





Avatar
michdenis
Bonjour Frédéric,

Essaie ceci :



Set BarForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With BarForm
.Properties("Caption") = " OF " & N
.Properties("Width") = 130
.Properties("Height") = 150
End With

'label sur userform
With BarForm.Designer
Set L1 = .Controls.Add("forms.label.1", "Label1", True)
With L1
.Caption = "Produit"
.Left = 5
.Top = 5
.Width = 120
.Height = 18
.Name = "Label1"
.Font.Bold = True
.Font.Size = 10
End With
Set L2 = .Controls.Add("forms.label.1", "Label2", True)
With L2
.Caption = "Quantité"
.Left = 1
.Top = 50
.Width = 50
.Height = 18
.Name = "Label2"
.Font.Bold = True
.Font.Size = 10
End With
Set L3 = .Controls.Add("forms.label.1", "Label3", True)
With L3
.Caption = "Délai"
.Left = 1
.Top = 70
.Width = 50
.Height = 18
.Name = "Label3"
.Font.Bold = True
.Font.Size = 10
End With
'textbox sur userform
Set T1 = .Controls.Add("forms.textbox.1", "textbox1", True)
With T1
.Text = p
.Left = 5
.Top = 25
.Width = 120
.Height = 18
.Name = "textbox1"
.Font.Bold = True
.Font.Size = 10
End With
Set T2 = .Controls.Add("forms.textbox.1", "textbox2", True)
With T2
.Text = q
.Left = 55
.Top = 50
.Width = 44
.Height = 18
.Name = "textbox2"
.Font.Bold = True
.Font.Size = 10
End With
Set T3 = .Controls.Add("forms.textbox.1", "textbox3", True)
With T3
.Text = Worksheets("CommandeCLIENT").Range("E1000").End(xlUp).Value
.Left = 55
.Top = 70
.Width = 44
.Height = 18
.Name = "textbox3"
.Font.Bold = True
.Font.Size = 10
End With
End With
VBA.UserForms.Add(BarForm.Name).Show

'Pour supprimer le formulaire
ThisWorkbook.VBProject.VBComponents.Remove BarForm



Salutations!




"Frederic" a écrit dans le message de news:

Merci pour ta réponse. En effet j'avais mis de coté ce probleme, et mesrci de
m'apporter la méthode.
Par contre as tu une idée pour lmon probleme précédement exprimé?
L'erreur apparait ici
'label sur userform
Set L1 = BarForm.Controls.Add("forms.label.1", "Label1", True)
C'est une erreur par rapport à l'objet.

J'avais essayé de mettre lors de la création du form sa
.Properties("Name")="of"& N
Mais j'avais alors une erreur pour le nom.

C'est pourtant l'architecture que je doit avoir afin de pouvoir, lors de la
déclaration de fab, appeler et supprimer l' of concerné.

Peut tu m'aider.
Je potasse en attendant la propriete Find.
Merci

Bonjour Frédéric,

Je n'ai pas testé ton code... mais tu dois avoir un problème là :

q = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value -
Worksheets("STOCKprod").Range("A3:D" &
Range("A1000").End(xlUp).Row).Find(p).Offset(0, 3).Value

ça devrait plutôt ressembler à ceci :


s = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value
with Worksheets("STOCKprod")
With .Range("A3:D" & .Range("A1000").End(xlUp).Row).
r= .Find(p).Offset(0, 3).Value
End with
End with
Q = S - R

Il doit y avoir un point devant chaque "Range" pour siginifier quelle est la
feuille source de la plage.
..Range("A3:D" & .Range("A1000").End(xlUp).Row).


P.S. La méthode Find ... si tu n'utilises pas certains PARAMÈTRES va finir par te causer
des problèmes... prend le temps de lire dans l'aide toute l'information sur
cette méthode...

C'est spécial .... car la méthode recherche dans A3:Dx et peu importe où elle
trouve l'information (colonne) , tu extraits toujours la valeur 3 colonnes à droite !!!! ?


Salutations!






"Frederic" a écrit dans le message de news:

Bonjour à tous, j'ai a nouveau besoin d'aide!
Je crée de maniére dynamique un form représentant un Ordre de Fab. Celui ci
est donc toujours le meme, sauf son nom et intitulé qui change.Ensuite , je
crée par code les labels et textbox de ce form.
Mon proble est que le nom du form est lié à une variable et le code me
retourne une erreur a cause du nom.
Voici mon code: Si quelqu'un pouvait m'aider.
Merci
Dim BarForm As Object, p As Variant, q As Integer, N As Variant
Dim L1 As MSForms.Label, L2 As MSForms.Label, L3 As MSForms.Label
Dim T1 As MSForms.textbox, T2 As MSForms.textbox, T3 As MSForms.textbox


Function CreationOF()
Dim q As Integer, p As Variant

p = Worksheets("CommandeCLIENT").Range("C1000").End(xlUp).Value
q = Worksheets("CommandeCLIENT").Range("D1000").End(xlUp).Value -
Worksheets("STOCKprod").Range("A3:D" &
Range("A1000").End(xlUp).Row).Find(p).Offset(0, 3).Value
N = Worksheets("CommandeCLIENT").Range("A1000").End(xlUp).Value


'userform

Set BarForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With BarForm
.Properties("Caption") = " OF " & N
.Properties("Width") = 130
.Properties("Height") = 150
End With

'label sur userform
Set L1 = BarForm.Controls.Add("forms.label.1", "Label1", True)
With L1
.Text = "Produit"
.Left = 5
.Top = 5
.Width = 120
.Height = 18
.Name = "Label1"
.Font.Bold = True
.Font.Size = 10
End With
Set L2 = BarForm.Controls.Add("forms.label.1", "Label2", True)
With L2
.Text = "Quantité"
.Left = 1
.Top = 50
.Width = 50
.Height = 18
.Name = "Label2"
.Font.Bold = True
.Font.Size = 10
End With
Set L3 = BarForm.Controls.Add("forms.label.1", "Label3", True)
With L3
.Text = "Délai"
.Left = 1
.Top = 70
.Width = 50
.Height = 18
.Name = "Label3"
.Font.Bold = True
.Font.Size = 10
End With
'textbox sur userform
Set T1 = BarForm.Controls.Add("forms.textbox.1", "textbox1", True)
With T1
.Text = p
.Left = 5
.Top = 25
.Width = 120
.Height = 18
.Name = "textbox1"
.Font.Bold = True
.Font.Size = 10
End With
Set T2 = BarForm.Controls.Add("forms.textbox.1", "textbox2", True)
With T2
.Text = q
.Left = 55
.Top = 50
.Width = 44
.Height = 18
.Name = "textbox2"
.Font.Bold = True
.Font.Size = 10
End With
Set T3 = BarForm.Controls.Add("forms.textbox.1", "textbox3", True)
With T3
.Text > Worksheets("CommandeCLIENT").Range("E1000").End(xlUp).Value
.Left = 55
.Top = 70
.Width = 44
.Height = 18
.Name = "textbox3"
.Font.Bold = True
.Font.Size = 10
End With

End Function