I'm trying to add dynamic controls to different frames in a UserForm. I'm working on Outlook 2016.
I want them to be displayed by row of 3 in each frame I have for each user I have and then 3 others right below the first and so on. Example :
Frame1 Frame2
Label1 Label2 Label3 Label1 Label2 Label3
-user1 -user1 -user1 -user1 -user1 -user1
-user2 -user2 -user2 -user2 -user2 -user2
...
What I get now is https://i.stack.imgur.com/4VBnw.jpg
With my example this would look like this :
Frame1
Label1 Label2 Label3
-lastUserOfTheList -lastUserOfTheList -lastUserOfTheList
Code :
At the time being, I'm able to create my controls but they all seem to overlap even though I'm setting their Left and Top properties.
I do set a new control with this :
Set opBtn = Me.Frame1.Controls.Add("Forms.OptionButton.1")
And then I set the properties by calling another sub which I give some arguments :
Call setControlProperties(userNumber, optionButtonCaption, opBtn, x)
This sub does contain :
With opBtn
.Left = x * 36
.Top = 18 + (userNumber * 18)
.Caption = optionButtonCaption
.Height = 36
.Width = 48
.ZOrder (0)
End With
x
is an integer variable I use to increment the Left property so the controls don't overlap (but for now they do). userNumber
is another integer variable that I use to increment the Top property. Each user has its own "Top value". OpBtn
is a MSForms.Control variable.
I'm sure my frames are wide enough to host the dynamic controls.
Question : My question is the following : Does anyone know why theses controls overlap despite the fact I'm setting their .Top and .Left property to be different ?
PS : This is my first post here so I hope I did not forget anything.
Edit 1 : I put the code contained in setControlProperties right after the
Set opBtn = Me.Frame1.Controls.Add("Forms.OptionButton.1")
as suggested but it does still overlap. No further progress for now.
Edit 2 : I added the property GroupName to my opBtn control and now some controls are a bit exceeding from the overlap. I'm now sure it is an overlap but I still can't figure out why.
Edit 3 : I used the watch window along with f8(line by line) to observe the value of my opBtn.Left and opBtn.Top during the execution. Both are always correctly incremented. I also tried to modifiy every OptionButton object proprety but I always get the same result.
Edit 4 : I added a name and forced the control to be visible but this had no effect.
Set opBtn = Me.Frame1.Controls.Add("Forms.OptionButton.1", "dynamicButton" & x, True)