Textbox in a frame

Balou -  
 Balou -
Hello everyone, I need your help and to learn
Novice in VBA, I am still looking to create a file in which I want to use a userform.
After searching online, I created a userform where several textboxes are displayed based on a variable.
So far, everything works.
Now I would like the textboxes to be integrated into a frame.
But the textboxes are displayed outside the frame.

Here is the code, thank you for your suggestions.

Incr = 8
PosX = 120

For i = 1 To nbcells 'loop for the creation of the TextBox

Set Obj = Me.Controls.Add("forms.Frame.1")
With Obj
.Caption = "TRACABILITE"
.Font.Bold = True
.Left = 6
.Top = 126
.Width = 114
.Height = 100

Set Obj = Me.Controls.Add("forms.TextBox.1")
With Obj
.Name = "TextBox" & i
.Object.Value = " "
.Left = PosX
.Top = 30 * ((i - 1) Mod 10) + 40
.Width = 100
.Height = 20
End With

'adding the object to the class
Set Cl = New Classe1
Set Cl.TextBox = Obj
Collect.Add Cl
If i Mod 10 = 0 Then PosX = PosX + 150
Incr = Incr + 1
End With
Next i


Thank you for your help, have a nice day.

4 answers

thev Posted messages 2005 Registration date   Status Member Last intervention   722
 
This should work better


Set Frame1 = Me.Controls.Add("forms.Frame.1")
With Frame1
.Caption = "TRACEABILITY"
.Font.Bold = True
.Left = 6
.Top = 126
.Width = 114
.Height = 100
End With
For i = 1 To nbcells
Set Obj = Frame1.Controls.Add("forms.TextBox.1")
With Obj
.Name = "TextBox" & i
.Object.Value = " "
.Left = PosX
.Top = 30 * ((i - 1) Mod 10) + 40
.Width = 100
.Height = 20
End With
Next i


--
1
thev Posted messages 2005 Registration date   Status Member Last intervention   722
 
Hello,

Try this

Set Obj = Me.Controls.Add("forms.Frame1")
With Obj
.Caption = "TRACEABILITY"
.Font.Bold = True
.Left = 6
.Top = 126
.Width = 114
.Height = 100
End With
Set Obj = Me.Frame1.Controls.Add("forms.TextBox0")
With Obj
.Name = "TextBox" & i
.Object.Value = " "
.Left = PosX
.Top = 30 * ((i - 1) Mod 10) + 40
.Width = 100
.Height = 20
End With

--
 
0
Balou
 
Thank you thev for your post, but your suggestion doesn't work.

This line creates an error if I leave TextBox0
Set Obj = Me.Frame1.Controls.Add("forms.TextBox0")


I tested with TextBox.1, no more error, but the TextBoxes are no longer displayed.

I continue to search on my side.

Looking forward to your response, thank you for your help.
0
Balou
 
Hello thev, this solution works.

Thank you for your support.
0